Vuejs 2数据绑定失败

问题描述 投票:-1回答:1

我不明白为什么它不起作用这让我发疯

<template>
    <p>{{ greeting }}</p>
</template>

<script>
    export default {
        name: 'App',
        data: function(){
          return {
            greeting: 'this is message'
          }
        }
    }
</script>

为什么{{ greeting }}不工作?它应该运行文本。但我得到了这个错误

错误编译模板:

组件模板应该只包含一个根元素。如果您在多个元素上使用v-if,请使用v-else-if来链接它们。

谁能帮我这个 ?

vue.js vuejs2 vue-component
1个回答
0
投票

你应该在你的<div>标签里面有一个app和一个id <template>

<template>
    <div id="app">{{greeting}}</div>
</template>

<script>
  export default {
    name: "App",
    data: function() {
    return {
      greeting: "this is message"
    };
   }
  };
</script>
© www.soinside.com 2019 - 2024. All rights reserved.