@xilonglab/vue-main 1.6.9 → 1.6.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xilonglab/vue-main",
3
- "version": "1.6.9",
3
+ "version": "1.6.11",
4
4
  "description": "xilong vue main",
5
5
  "main": "packages/index.js",
6
6
  "scripts": {
@@ -8,8 +8,8 @@ const emits = defineEmits(['change', 'update:modelValue'])
8
8
 
9
9
  const props = defineProps({
10
10
  modelValue: {
11
- type: String,
12
- default: ''
11
+ type: Array,
12
+ default: () => []
13
13
  },
14
14
  editable: {
15
15
  type: Boolean,
@@ -25,20 +25,10 @@ const props = defineProps({
25
25
  }
26
26
  })
27
27
 
28
- const tags = computed({
29
- get() {
30
- if (typeof props.modelValue == 'string') {
31
- if (props.modelValue.length !== 0) {
32
- return props.modelValue.split(',');
33
- }
34
- }
35
- return []
36
- },
37
- set(data) {
38
- emits('change', data.join(','))
39
- emits('update:modelValue', data.join(','))
40
- },
41
- });
28
+ function updateValue(data) {
29
+ emits('change', data)
30
+ emits('update:modelValue', data)
31
+ }
42
32
 
43
33
  const valueMap = computed(() => {
44
34
  let tmp = {};
@@ -52,16 +42,15 @@ const newTag = ref('')
52
42
 
53
43
  const handlers = {
54
44
  add() {
55
- const temp = tags.value.slice()
45
+ const temp = Array.isArray(props.modelValue) ? props.modelValue.slice() : []
56
46
  temp.push(newTag.value);
57
- tags.value = temp
47
+ updateValue(temp)
58
48
  newTag.value = ''
59
49
  },
60
50
  remove(index) {
61
- tags.value.splice(index, 1)
62
- const temp = tags.value.slice()
51
+ const temp = Array.isArray(props.modelValue) ? props.modelValue.slice() : []
63
52
  temp.splice(index, 1);
64
- tags.value = temp
53
+ updateValue(temp)
65
54
  }
66
55
  }
67
56
  </script>
@@ -69,7 +58,7 @@ const handlers = {
69
58
 
70
59
  <template>
71
60
  <div class="xl-tags">
72
- <el-tag v-for="(tag, index) in tags" :key="tag" :closable="editable" @close="handlers.remove(index)">
61
+ <el-tag v-for="(tag, index) in modelValue" :key="tag" :closable="editable" @close="handlers.remove(index)">
73
62
  {{ type == 'select' ? valueMap[tag] : tag }}
74
63
  </el-tag>
75
64
  <xl-input v-if="editable && type == 'input'" class="new-tag" v-model="newTag" />