有什麼辦法可以將數據隱式傳遞給父級的所有子組件嗎?我在React中尋找類似context
的東西。這裏是什麼,我試圖完成一個簡單的例子:如何將數據隱式傳遞給Vue中的所有子組件?
<body>
<my-component :my-prop="foo"></my-component>
<my-component :my-prop="bar"></my-component>
</body>
-
import MyComponent from './my-component';
new Vue({
el: 'body',
components: {
MyComponent,
},
});
我想所有my-component
的孩子不得不myProp
訪問,而無需通過它記下來時間。 $root
聽起來像一個好主意,但是接下來我不得不爲網頁上的每個組件創建一個虛擬主機,這也感覺不太好。
你可以使用事件嗎? – gurghet