最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

template or render function not defined.

標(biāo)簽:
Vue.js

下午写 Vue $parent 实例时,总是遇到这个问题,不禁让人陷入沉思


240

1.gif

Vue,醒醒啊,你怎么了,贴上子组件源代码

<template>
  <div>
    <child-component1></child-component1>
    <child-component2></child-component2>
    <button v-on:click="showChildComponentData">显示子组件的数据</button>
  </div></template><script>export default{  components: {    'child-component1': {      template: '#child-component1',      data: function () {        return {          msg: 'child component 111111'
        }
      }
    },    'child-component2': {      template: '#child-component2',      data: function () {        return {          msg: 'child component 222222'
        }
      }
    }
  },  methods: {    showChildComponentData: function () {      for (var i = 0; i < this.$children.length; i++) {
        alert(this.$children[i].msg)
      }
    }
  }
}</script>

这是报错信息:


660

1.png

修改后的代码:

<template>
  <div>
    <child-component1></child-component1>
    <child-component2></child-component2>
    <button v-on:click="showChildComponentData">显示子组件的数据</button>
  </div></template><script>export default{  components: {    'child-component1': {      template: '<p>I am ok</p>',      data: function () {        return {          msg: 'child component 111111'
        }
      }
    },    'child-component2': {      template: '<p>ok</p>',      data: function () {        return {          msg: 'child component 222222'
        }
      }
    }
  },  methods: {    showChildComponentData: function () {      for (var i = 0; i < this.$children.length; i++) {
        alert(this.$children[i].msg)
      }
    }
  }
}</script>

这样就好了,原因是 Vue 的构建,运行时构建删除了模板编译的功能,因此无法支持带 template 属性的 Vue 实例选项。



作者:H_婷
链接:https://www.jianshu.com/p/ecc97f18286c


點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消