update 优化 !pr417 解决部分问题 支持vue3版本
This commit is contained in:
parent
3b498c4939
commit
f2200df15a
@ -41,34 +41,30 @@ const props = defineProps({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
separator: {
|
||||||
|
type: String,
|
||||||
|
default: ",",
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const values = computed(() => {
|
const values = computed(() => {
|
||||||
if (props.value !== null && typeof props.value !== 'undefined') {
|
if (props.value === null || typeof props.value === 'undefined' || props.value === '') return [];
|
||||||
return Array.isArray(props.value) ? props.value : [String(props.value)];
|
return Array.isArray(props.value) ? props.value.map(item => '' + item) : String(props.value).split(props.separator);
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const unmatch = computed(() => {
|
const unmatch = computed(() => {
|
||||||
unmatchArray.value = [];
|
unmatchArray.value = [];
|
||||||
if (props.value !== null && typeof props.value !== "undefined") {
|
|
||||||
// 传入值为非数组
|
|
||||||
if (!Array.isArray(props.value)) {
|
|
||||||
if (props.options.some((v) => v.value == props.value)) return false;
|
|
||||||
unmatchArray.value.push(props.value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 传入值为Array
|
|
||||||
props.value.forEach((item) => {
|
|
||||||
if (!props.options.some((v) => v.value == item))
|
|
||||||
unmatchArray.value.push(item);
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 没有value不显示
|
// 没有value不显示
|
||||||
return false;
|
if (props.value === null || typeof props.value === 'undefined' || props.value === '' || props.options.length === 0) return false
|
||||||
|
// 传入值为数组
|
||||||
|
let unmatch = false // 添加一个标志来判断是否有未匹配项
|
||||||
|
values.value.forEach(item => {
|
||||||
|
if (!props.options.some(v => v.value === item)) {
|
||||||
|
unmatchArray.value.push(item)
|
||||||
|
unmatch = true // 如果有未匹配项,将标志设置为true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return unmatch // 返回标志的值
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleArray(array) {
|
function handleArray(array) {
|
||||||
|
@ -53,13 +53,13 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
values() {
|
values() {
|
||||||
if (this.value === null || typeof this.value !== 'undefined' || this.value === '') return []
|
if (this.value === null || typeof this.value === 'undefined' || this.value === '') return []
|
||||||
return Array.isArray(this.value) ? this.value.map(item => '' + item) : String(this.value).split(this.separator)
|
return Array.isArray(this.value) ? this.value.map(item => '' + item) : String(this.value).split(this.separator)
|
||||||
},
|
},
|
||||||
unmatch() {
|
unmatch() {
|
||||||
this.unmatchArray = []
|
this.unmatchArray = []
|
||||||
// 没有value不显示
|
// 没有value不显示
|
||||||
if (this.value === null || typeof this.value !== 'undefined' || this.value === '' || this.options.length === 0) return false
|
if (this.value === null || typeof this.value === 'undefined' || this.value === '' || this.options.length === 0) return false
|
||||||
// 传入值为数组
|
// 传入值为数组
|
||||||
let unmatch = false // 添加一个标志来判断是否有未匹配项
|
let unmatch = false // 添加一个标志来判断是否有未匹配项
|
||||||
this.values.forEach(item => {
|
this.values.forEach(item => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user