How to add object attributes dynamically by vue
This article mainly introduces "how to add object attributes dynamically by vue". In daily operation, I believe many people have doubts about how to add object attributes dynamically by vue. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to add object attributes dynamically by vue". Next, please follow the editor to study!
The specific methods are as follows:
1. Use the this.$set (obj,key,value) method to dynamically add properties to basic data types and objects
This.$set (this.obj, key, value); / / add an attribute
This.obj=Object.assign ({}, this.obj, {aburet 1); / / add multiple attributes
two。 Dynamically add attributes to an array using index values
Var vm=new Vue ({
Data: {
List: ['axiajiajiaoyuzhongyuanjiaoyuanshou]
}
});
Vm.list [1] ='x'
Vm.list.length=0
Vm.$set (vm.list,1,'x')
Vm.list.splice (1 ~ (1) ~ ~ x')
Splice (index,howmany,newValue1,newValue2)
At this point, the study on "how to dynamically add object properties to vue" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!