Property or method city 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
This error message occurs when Vue is unable to find a reactive property or method called "city" on the component instance during rendering. To resolve this issue, ensure that the "city" property is declared as reactive either in the data option or as a computed property on the component instance.
For example, if you want to declare "city" as a reactive property in the data option, you can do the following:
<template>
<div>{{ city }}</div>
</template>
<script>
export default {
data() {
return {
city: 'New York'
}
}
}
</script>
Alternatively, if you want to declare "city" as a computed property that depends on some other reactive property, you can do the following:
<template>
<div>{{ cityName }}</div>
</template>
<script>
export default {
data() {
return {
state: 'NY'
}
},
computed: {
cityName() {
return this.state === 'NY' ? 'New York' : 'Unknown'
}
}
}
</script>
Either way, it is important to ensure that all reactive properties are properly declared and initialized to avoid this error message.
原文地址: https://www.cveoy.top/t/topic/bd2J 著作权归作者所有。请勿转载和采集!