鍍金池/ 問答/HTML/ 為什么vue component 的模版無法顯示出來呢?

為什么vue component 的模版無法顯示出來呢?

在寫vue component的時候遇到一個問題,就是模版沒法顯示,還沒有報錯~~~試過很多辦法依然顯示不出來,崩潰了,來這邊求助各位前輩!十分感謝!

<div id="app">
    {{a}}   //這里能顯示1
  </div>
  <template id="aaa">
   <h3 @click="show()">{{msg}}</h3> //這部分無法顯示
  </template>
const vm = new Vue({
        el: '#app',
        data: {
          a: 1
        },
        components: {
          //組件名
          'my-aaa': {
            data() {
              return {
                msg: 'welcome'
              }
            },
            methods: {
              show() {
                this.msg = 'woof'
              }
            },
            template: '#aaa'
          },
        }
      })
回答
編輯回答
空痕
<div id="app">
{{a}}   //這里能顯示1
<my-aaa />
</div>
<template id="aaa">
<h3 @click="show()">{{msg}}</h3> //這部分無法顯示
</template>

你定義了組件,但是并沒有在 vm 的節(jié)點上引用。所以就沒顯示出來

2017年5月1日 00:23