I'm having a problem that I see really lots of people having but I simple can't solve it from the similar questions I've found.
I'm using a v-for
in a Vue Component and the value of the array always gives me a warning saying that variable is missing:
[Vue warn]: Property or method "text" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
I've created a jsfidle for it:
<template>
<section>
<section :v-for="text in texts">{{text}}</section>
</section>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
@Component<Map>({
data() {
return {
texts: ["bbbbb", "xxxxx"]
};
}
})
export default class Map extends Vue {}
</script>
If I change the {{text}}
to {{texts[0]}}
(see it in https://jsfiddle.net/hdm7t60c/3/) I get bbbbb
but it doesn't iterate and I get the error too.
This is the tip of the iceberg on a problem I'm having, but maybe if I solve this, I can get everything right.
[vue3] Property xxx was accessed during render but is not defined on instance. In Vue. js, the error generally means you are referring to a variable which could be a data, prop, method or computed property in your template, but it's not defined in your component script.
The Composition API allows author to Vue components using imported functions rather than declarative functions. Composition API allows us to write clean, logical, and efficient code. The composition API also has better minification in the build process compared to the options API with equivalent code.
Mutating props in Vue is an anti-pattern In Vue, we pass data down the the component tree using props. A parent component will use props to pass data down to it's children components. Those components in turn pass data down another layer, and so on. Then, to pass data back up the component tree, we use events.
Try to remove the binding sign :
from v-for
directive, and you should also specify the key attribute :
<template>
<section>
<section v-for="(text,index) in texts" :key="index">{{text}}</section>
</section>
</template>
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