我在使用vuelidate时遇到了一个奇怪的问题。
例如,我在data()中定义了这个对象数组:
arrOfObj = [{a: 1},{b: 2},{c: 3}]
我想要做的是在这个对象数组中添加'Required'(vuelidate)属性,如下所示:
验证(){
let array = this.arrOfObj;
let result = array.map(function(obj){return Object.assign(obj, {required: true})})
console.log("New Array: ", result);
return {
indexKey: {
required
},
defValues: result //Here is where I think the issue is
}
},
只有在添加此行时:
defValues: result //Here is where I think the issue is
我知道这个错误:
nextTick中的错误:"TypeError: path.split不是函数“
有什么建议吗?
发布于 2021-11-21 00:29:47
尝试省略:true
а寄存,以使用您的导入:
Object.assign(obj, {required})
也许您的defaultValue
需要字符串,而不是对象。或者期望对象中有一个名为path
的字符串成员。
另一个问题。
您的object.assign正在覆盖您的源。使用空对象初始化,或使用扩展运算符。
let result = array.map(function(obj){
return Object.assign({}, obj, {required: true})
})
let result = array.map(function(obj){
return {...obj, required: true}
})
https://stackoverflow.com/questions/70034588
复制