/** * 字典数据处理插件 */ import Vue from 'vue'; import _ from 'lodash'; import assert from 'assert'; const Plugin = { install(vue, options) { // 4. 添加实例方法 vue.prototype.$policy = function(key) { assert(_.isString(key)); const state = this.$store.state.naf.policy; if (!state) { throw new Error("can't find store for naf policy"); } for (const i in state.items) { if (state.items[i].key == key) { return state.items[i].value; } else { return 0; } } }; }, }; Vue.use(Plugin);