how do I declare an array of structures in the data of vue?
...
data () {
return {
structArray: [],// 1
unit: {id: "", name: ""},
structArray2: unit[10]// 2
}
}
...
as above, what if you want structArray to be an array of structs, such as
[{id: "1arrays, name: "a"}, {id:" 2codes, name: "b"}, {id: "3codes, name: "c"}]
? If
declares it as 1, structArray [0] .id ="1"
will have an undefined error, that is, the variable is not initialized. If
uses the method of 2, you need to specify the number of elements in the array, which is not allowed as structArray2: unit []
.
Note that the number of elements in the array is not known at the initial moment, but the element structure {id:"", name:""}
is known.