|
1 |
| -# data dict for Vue.js |
2 |
| - |
3 |
| -## Installation |
4 |
| - |
5 |
| -```js |
6 |
| -npm i vue-data-dict -S |
7 |
| -``` |
8 |
| - |
9 |
| -## Examples |
10 |
| - |
11 |
| -### install |
12 |
| - |
13 |
| -```vue |
14 |
| -import Vue from 'vue' |
15 |
| -import VueDataDict from 'vue-data-dict' |
16 |
| -
|
17 |
| -Vue.use(VueDataDict, { |
18 |
| - onCreated(dict) { |
19 |
| - console.log('dict created: %o', dict) |
20 |
| - }, |
21 |
| - onReady(dict) { |
22 |
| - console.log('dict ready: %o', dict) |
23 |
| - }, |
24 |
| - metas: { |
25 |
| - '*': { |
26 |
| - request(dictMeta) { |
27 |
| - return Promise // get data from remote server |
28 |
| - }, |
29 |
| - responseConverter(response, dictMeta) { |
30 |
| - // you can use "VueDataDict.DictConverter({ ... }, dictMeta)" to convert Object to DictData |
31 |
| - return [] // Array.<DictData> |
32 |
| - } |
33 |
| - } |
34 |
| - } |
35 |
| -}) |
36 |
| -``` |
37 |
| - |
38 |
| -### use |
39 |
| - |
40 |
| -```vue |
41 |
| -<template> |
42 |
| - <div> |
43 |
| - <div v-for="item in dict.dict.dict1" :key="item.value"> |
44 |
| - {{ item.label }} |
45 |
| - </div> |
46 |
| - </div> |
47 |
| -</template> |
48 |
| -
|
49 |
| -<script> |
50 |
| -export default { |
51 |
| - dicts: [ |
52 |
| - 'dict1', // only type name |
53 |
| - { // full dict meta |
54 |
| - type: 'dict2', |
55 |
| - lazy: true, // lazy load |
56 |
| - request(dictMeta) { // get dict2's data |
57 |
| - ... |
58 |
| - return Promise |
59 |
| - }, |
60 |
| - responseConverter(response, dictMeta) { |
61 |
| - ... |
62 |
| - return [] // Array.<DictData> |
63 |
| - }) |
64 |
| - }], |
65 |
| - methods: { |
66 |
| - onDictReady(dict) { |
67 |
| - // dict ready event |
68 |
| - }, |
69 |
| - toLoadDict() { |
70 |
| - this.dict.reloadDict('dict2') |
71 |
| - }, |
72 |
| - } |
73 |
| -} |
74 |
| -</script> |
| 1 | +# data dict for Vue.js |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +```js |
| 6 | +npm i vue-data-dict -S |
| 7 | +``` |
| 8 | + |
| 9 | +## Examples |
| 10 | + |
| 11 | +### install |
| 12 | + |
| 13 | +```vue |
| 14 | +import Vue from 'vue' |
| 15 | +import VueDataDict from 'vue-data-dict' |
| 16 | +
|
| 17 | +Vue.use(VueDataDict, { |
| 18 | + onCreated(dict) { |
| 19 | + console.log('dict created: %o', dict) |
| 20 | + }, |
| 21 | + onReady(dict) { |
| 22 | + console.log('dict ready: %o', dict) |
| 23 | + }, |
| 24 | + metas: { |
| 25 | + '*': { |
| 26 | + request(dictMeta) { |
| 27 | + return Promise // get data from remote server |
| 28 | + }, |
| 29 | + responseConverter(response, dictMeta) { |
| 30 | + // you can use "VueDataDict.DictConverter({ ... }, dictMeta)" to convert Object to DictData |
| 31 | + return [] // Array.<DictData> |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | +}) |
| 36 | +``` |
| 37 | + |
| 38 | +### use |
| 39 | + |
| 40 | +```vue |
| 41 | +<template> |
| 42 | + <div> |
| 43 | + <div v-for="item in dict.dict.dict1" :key="item.value"> |
| 44 | + {{ item.label }} |
| 45 | + </div> |
| 46 | + </div> |
| 47 | +</template> |
| 48 | +
|
| 49 | +<script> |
| 50 | +export default { |
| 51 | + dicts: [ |
| 52 | + 'dict1', // only type name |
| 53 | + { // full dict meta |
| 54 | + type: 'dict2', |
| 55 | + lazy: true, // lazy load |
| 56 | + request(dictMeta) { // get dict2's data |
| 57 | + ... |
| 58 | + return Promise |
| 59 | + }, |
| 60 | + responseConverter(response, dictMeta) { |
| 61 | + ... |
| 62 | + return [] // Array.<DictData> |
| 63 | + }) |
| 64 | + }], |
| 65 | + methods: { |
| 66 | + onDictReady(dict) { |
| 67 | + // dict ready event |
| 68 | + }, |
| 69 | + toLoadDict() { |
| 70 | + this.dict.reload('dict2').then(dict => { |
| 71 | + // do something |
| 72 | + }) |
| 73 | + }, |
| 74 | + toRegisterDict() { |
| 75 | + this.dict.register('dict3').then(dict => { |
| 76 | + // do something |
| 77 | + }) |
| 78 | + }, |
| 79 | + toWaitDict() { |
| 80 | + this.dict.wait('dict1').then(dict => { |
| 81 | + // do something |
| 82 | + }) |
| 83 | + }, |
| 84 | + } |
| 85 | +} |
| 86 | +</script> |
75 | 87 | ```
|
0 commit comments