Appearance
配置
js
// config.js
import irdict from "../../../dist/irdict";
import request from "../request";
const config = new irdict({
labelKey: "dictLabel",
valueKey: "dictValue",
remoteMethod: (dictKey, addDictItme) => {
request.get("/api/system/dict/data/type/" + dictKey).then((res) => {
addDictItme(dictKey, res.data);
});
},
});
/**
*
* instance.getDictList(dictKey)
* instance.getDictLabel(dictKey, dictValue)
* instance.addDictItme(dictKey, list)
* */
const instance = config.create(vue);
export default instance
/**
* 以 Vue 插件使用
* */
// const instance = config.create(vue);
// 直接导出config
export default config
// main.js
// 在 main.js 导入使用
import dictConfig from "./util/dict";
Vue.use(dictConfig);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
js
// 使用
this.$getDictList(dictKey)
this.$getDictLabel(dictKey, dictValue)
this.$addDictItme(dictKey, list)
1
2
3
4
2
3
4
source code
js
// source code
"use strict";
import Dict from "./main/index.js";
class dictConfig {
constructor(config) {
this._config = config;
}
install = (Vue) => {
const instance = new Dict(Vue, this._config);
Vue.prototype.$getDictList = instance.getDictList;
Vue.prototype.$getDictLabel = instance.getDictLabel;
Vue.prototype.$addDictItme = instance.addDictItme;
return instance;
};
create = (Vue) => {
return new Dict(Vue, this._config);
};
}
export default dictConfig;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23