基本的Vue.js示例不起作用

问题描述 投票:0回答:3

我有这个超级基本的起点:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>

    <link rel="stylesheet" type="text/css" href="Content/dictionary.css" />

    <script src="Scripts/kuroshiro.min.js"></script>
</head>
<body>
    <div id="searchResultsVue">
        <table>
            <tr v-for="r in results">
                {{ r.Result.ent_seq }}
            </tr>
        </table>
    </div>


    <script src="https://vuejs.org/js/vue.js"></script>
    <script>


        var searchResultsVue = new Vue({
            el: '#searchResultsVue',
            data: { results: [{ Result: { ent_seq: 'asd' } }] }
        });
    </script>
</body>
</html>

但我明白了

[Vue警告]:属性或方法“r”未在实例上定义,但在呈现期间引用。通过初始化属性,确保此属性在数据选项或基于类的组件中是被动的。见:https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties

我不明白

javascript data-binding vue.js
3个回答
1
投票

这是HTML宽松渲染实践的问题。当它为一个表构建Dom元素时,它期望某个结构,并且任何偏离该结构的东西都被推到定义之外。

所以

    <table>
        <tr v-for="r in results">
            {{ r.Result.ent_seq }}
        </tr>
    </table>

像这样的行为

    <table>
        <tr v-for="r in results">
        </tr>
    </table>
    {{ r.Result.ent_seq }}

然后错误是它在循环外看到对循环变量的调用。

As seen in this fiddle在代码周围添加表定义标记会阻止它被推送。


1
投票

你需要修复你的标记。 tr需要td作为其孩子才能正常工作。

<tr v-for="r in results">
  <td>{{ r.Result.ent_seq }}</td>
</tr>

1
投票

你必须在tr里面使用td标签。表格行似乎有些特别之处

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <div id="searchResultsVue">
        <table>
            <tr v-for="r in results">
                <td>{{ r.Result.ent_seq }}</td>
            </tr>
        </table>
    </div>


    <script src="https://vuejs.org/js/vue.js"></script>
    <script>
        var searchResultsVue = new Vue({
            el: '#searchResultsVue',
            data: { results: [{ Result: { ent_seq: 'asd' } }] }
        });
    </script>
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.