I have this in vue data:
data() {
return {
names: [],
length: names.length,
}
But this does not work as RefereneError ( names is undefined ) is thrown. I used this.names but makes no difference.
You need to do something like this to make it work:
#1st way
data() {
let defaultNames = [];
return {
names: defaultNames,
length: defaultNames.length
}
}
#2nd way — using computed data (the better way):
data() {
return {
names: [],
}
},
computed: {
length() {
return this.names.length;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With