我是VUE JS的新手,在Codesandbox上的文档中使用示例。此代码显示我错误
[Vue warn]: Property or method "todos" 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. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
我无法检测到问题所在。
<template>
<div id="app">
<ol>
<li v-bind:key="todo.text" v-for="todo in todos">{{ todo.text }}</li>
</ol>
</div>
</template>
<script>
import Vue from "vue";
var app = new Vue({
el: "#app",
data: {
todos: [
{ text: "Learn JavaScript" },
{ text: "Learn Vue" },
{ text: "Build something awesome" }
]
}
});
</script>
<style>
style here
</style>
这是代码和问题的实时示例
这是更新的代码。您声明的todos变量不是在VUE中。
您应该在下面声明您的数据属性。
<template>
<div id="app">
<ol>
<li v-bind:key="todo.text" v-for="todo in todos">{{ todo.text }}</li>
</ol>
</div>
</template>
<script>
import HelloWorld from "./components/HelloWorld";
export default {
name: "App",
components: {
HelloWorld
},
data() {
return {
todos: [
{ text: "Learn JavaScript" },
{ text: "Learn Vue" },
{ text: "Build something awesome" }
]
};
}
};
https://codesandbox.io/s/9O2036km1r