vue中使用Vue.set()报错 Cannot convert undefined or null to object
使用Vue.set()直接在data上增加属性export default {data() {return {width: '100'}},methods: {scrollFn(e) {Vue.set(this.data, 'height', 0)}...
·
使用Vue.set()直接在data上增加属性
export default {
data() {
return {
width: '100'
}
},
methods: {
scrollFn(e) {
Vue.set(this.data, 'height', 0)
}
}
}
}
报错:
分析:不能在直接data上增加属性,可以在data里的对象上增加属性,例如:
export default {
data() {
return {
info: {
width: '100'
}
}
},
methods: {
scrollFn(e) {
Vue.set(this.info, 'height', 0)
}
}
}
}
拓展:
Vue.set() 响应式新增与修改数据
调用方法:Vue.set( target, key, value )
target:要更改的数据源(可以是对象或者数组)
key:要更改的具体数据
value :重新赋的值
更多推荐
已为社区贡献13条内容
所有评论(0)