The solution to vue.set() error: use [Vue.set()] to add attributes to the object in data, the code is [export default {data() {return {info: {width: '100'}}}].
The operating environment of this tutorial: Windows 7 system, Vue version 2.9.6, Dell G3 computer.
Solution to vue.set() error:
Use Vue.set()
Add attributes directly to data
export default { data() { return { width: '100' } }, methods: { scrollFn(e) { Vue.set(this.data, 'height', 0) } } } }
Error report:
Analysis: You cannot add attributes to direct data. You can add attributes to objects in data, for example:
export default { data() { return { info: { width: '100' } } }, methods: { scrollFn(e) { Vue.set(this.info, 'height', 0) } } } }
Expand :
Vue.set()
Responsive new and modified data
Calling method: Vue .set( target, key, value )
target
: The data source to be changed (can be an object or array)
key
: The specific data to be changed
value
: The value to be reassigned
Related free learning recommendations: javascript (video)
The above is the detailed content of What to do if vue.set() error occurs. For more information, please follow other related articles on the PHP Chinese website!