• 赚钱入口【需求资源】限时招募流量主、渠道主,站长合作;【合作模式】CPS长期分成,一次推广永久有收益。主动打款,不扣量;

Failed to mount component: template or render function not defined.

Vue cps12345 3周前 (10-08) 33次浏览 0个评论

报错:

Failed to mount component: template or render function not defined.

模板代码:

<template>
  <div id="app">
    <button v-on:click="addAnnotation()">Add annotation</button>
    <div v-for="(annotation, index) in annotations" :key="index">
      <component :is="annotation">
      </component>
    </div>
  </div>
</template>

<script>
import DraggableAnnotation from "./components/DraggableAnnotation.vue";

export default {
  name: "App",
  components: {
    DraggableAnnotation,
  },
  data: function () {
    return {
      annotations: [],
    };
  },
  methods: {
    addAnnotation: function () {
      this.annotations.push({ DraggableAnnotation });
    },
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

解决

cuz索引未定义

<div v-for="annotation in annotations" :key="index">

修改为

<div v-for="(annotation, index) in annotations" :key="index">

 

喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址