new Vue({
el: '#app',
data: {
name: 'Mary'
},
components: {
'hello': {
props: {
named: String
},
template: `<p>歡迎{{named}}來到Vue.js前端設計!</p>`
},
'goodbye': {
props: {
named: String
},
template: `<p>{{named}},再見,期待您很快就再回到Vue.js前端設計!</p>`
}
}
})
沒用過vue.js
會不會是因為is?? 您的第二章圖有is
<OOOO is="showsomething" :named="...">.....
還有就是您第二張圖下方的goodBye有props參數設定,您的showsomething宣告內沒有,所以vue根本不知道您有:named參數?? 把props參數移到showsomething內看看
components: {
'showsomething' :{
props: { named: String},
template:`<p>{{named}}...</p>`
}
}
這剛好有碰過
VUE的component 有個小毛病
它不能寫在 new Vue下面
new Vue({
el: '#app',
data: {
name: 'Tom'
},
props: {
named: String
},
components: {
'showsomething': {
template: `<p>{{named}}這不是我要的!</p>`
}
}
})
這樣一定出錯給你看 你必須
const showsomething = {
props: {
named: String
},
template: `<p>{{named}},再見,期待您很快就再回到Vue.js前端設計!</p>`
}
new Vue({
el: '#app',
data: {
name: 'Tom'
},
components: {
showsomething
}
})
就跟妳寫的一樣 寫在上面就好了XD
雖然有最佳了 還是把它打完整
![]()
你有沒有注意到你第2個寫法
裡面的prop是寫在compoments...
回覆咖冰啦:這不是Vue的小毛病喔,官方文件有說components需要註冊在根實例(也就是new Vue)之前!
引用自Vue官方文件:
....
Remember that global registration must take place before the root Vue instance is created (with new Vue)
.....
連結:https://vuejs.org/v2/guide/components-registration.html
雖然樓主已經有給最佳解但還是補充一下,如果內容有誤麻煩告知我XD
![]()
这些组件是全局注册的。也就是说它们在注册之后可以用在任何新创建的 Vue 根实例 (new Vue) 的模板中。
其實 Vue 的中文 document 寫得滿不錯的啊 ![]()
Remember that global registration must take place before the root Vue instance is created (with new Vue).
你可能跟這段搞混了
不過這段的意思也是全域註冊的組件要在建立根實例之前註冊
listennn08
嗯嗯,我是直接貼Vue pwa的內文,沒有切到簡體,下次會看仔細一點XD