Vue.js 教程:Vue.js 中的条件不起作用 - 未定义属性或方法

我正在尝试遵循本教程并复制代码。我唯一改变的是 index.js 的位置,这不应该是问题,因为 hello world 教程工作得很好。控制台输出以下内容:


[Vue warn]: Property or method "seen" 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.(found in <Root>)

所以我的问题是,index.js 文件中的这段代码是否有任何问题:


var app = new Vue({

  el: '#app',

  data: {

    seen: true

  }

})

或者html文件有问题(插入到markdown文件中,因此是标题部分)


---

title: vue

---

<html>

    <head>

        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    </head>

    <body>


        <div id="app">

            <span v-if="seen">Now you see me</span>

        </div>


        <script src="vue/index.js"></script>

    </body>

</html>

这可能是一个简单的错误,但我已经摆弄了两个小时。如果有人能帮助我那就太好了。


潇潇雨雨
浏览 127回答 2
2回答

翻过高山走不出你

我正在尝试遵循本教程并复制代码。我唯一改变的是 index.js 的位置,这不应该是问题,因为 hello world 教程工作得很好。控制台输出以下内容:[Vue warn]: Property or method "seen" 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.(found in <Root>)所以我的问题是,index.js 文件中的这段代码是否有任何问题:var app = new Vue({&nbsp; el: '#app',&nbsp; data: {&nbsp; &nbsp; seen: true&nbsp; }})或者html文件有问题(插入到markdown文件中,因此是标题部分)---title: vue---<html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp; <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <div id="app">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span v-if="seen">Now you see me</span>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <script src="vue/index.js"></script>&nbsp; &nbsp; </body></html>这可能是一个简单的错误,但我已经摆弄了两个小时。如果有人能帮助我那就太好了。

至尊宝的传说

如果您使用 CDN,您的代码应如下所示:<html><head>&nbsp; <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script></head><div id="app">&nbsp; <span v-if="seen">Now you see me</span></div><script type="text/javascript">&nbsp; new Vue({&nbsp; &nbsp; el: "#app",&nbsp; &nbsp; data() {&nbsp; &nbsp; &nbsp; return {&nbsp; &nbsp; &nbsp; &nbsp; seen: true,&nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; },&nbsp; });</script><style></style></html>您将数据定义为返回对象的函数。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript