How does vue define array objects
This article mainly introduces how vue defines array objects related knowledge, detailed and easy to understand, simple and fast operation, with certain reference value, I believe everyone will have some gains after reading this article how vue defines array objects, let's take a look at it.
The specific steps are as follows:
1. First, create a vue.js project in vue-cli;
vue create project-name
2.After the vue.js project is created, use the personQueryList method in the project to define an array object;
personQueryList(this.paramType).then(res => {
for (let i = 0; i
< res.records.length;="" i++)="">this.options[i] = {
label: res.records[i].name,
value: res.records[i].code
}
}
})
Related extensions:
1) De-duplication of array objects
methods:{
unique(arr) { //Filter array by unique identifier orderId
const res = new Map();
return arr.filter((arr) => ! res.has(arr.OrderId) && res.set(arr.OrderId, 1))
},
}
this.arr = this.unique(this.arr);
2. Sort array objects
created() {
this.$ axios.run(***, (res) => {
if (res.code === 0) {
this.arr= res.data;
this.arr.sort(this.compare('code'));
this.selectInit(res.data);
}
});
this.onInit();
},
methods: {
compare(property) {
return function(a, b) {
let value1 = a[property];
let value2 = b[property];
return value1 - value2;
};
},
About "vue how to define array object" the content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "how to define array objects in vue." If you still want to learn more knowledge, please pay attention to the industry information channel.