我有一個動態的觀點:傳遞道具動態動態組件在VueJS
<div id="myview">
<div :is="currentComponent"></div>
</div>
與相關Vue的實例:
new Vue ({
data: function() {
return {
currentComponent: 'myComponent',
}
},
}).$mount('#myview');
這使我能夠動態地改變我的組件。
在我的情況下,我有三個不同的組件:myComponent
,myComponent1
和myComponent2
。我喜歡這樣它們之間進行切換:現在
Vue.component('myComponent', {
template: "<button @click=\"$parent.currentComponent = 'myComponent1'\"></button>"
}
,我想道具傳遞給myComponent1
。
當我將組件類型更改爲myComponent1
時,如何傳遞這些道具?
您經由元件'PROPNAME = 「propValue」'上屬性傳遞道具。這是你的問題嗎? – thanksd
我不能因爲我從不寫''myComponent1 propName =「propValue」>'我用'$ parent.currentComponent = componentName'以編程方式更改組件 – Epitouille
是的,但是你寫'
'。這就是你添加屬性的地方。 – thanksd