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