鍍金池/ 問答/HTML/ vue2中子組件里利用slot引入另一個子組件時,這個子組件的ref怎么獲取到

vue2中子組件里利用slot引入另一個子組件時,這個子組件的ref怎么獲取到

clipboard.png

clipboard.png

pop-up是一個彈出框的組件,彈出框內部有一個<slot></slot>供父組件插入模板,common-input是輸入框的一個組件,當執(zhí)行點擊按鈕彈出pop-up的方法時,this.$refs.popup可以獲取到值,而this.$refs.input0位undefined。

clipboard.png

請問這個this.$refs.input0怎么獲取到?

//編輯
直接console.log(this.$refs)和console.log(this.$refs.input0)的結果。

clipboard.png

在this.$refs中是存在input0的

當用一個計時器異步輸出this.$refs.input0時是有結果的
clipboard.png

clipboard.png

請問這是什么原因?有沒有更好的解決辦法?

回答
編輯回答
落殤

你把0去掉試試

2018年4月2日 07:47
編輯回答
伴謊

我也是看答案的,遇到的問題和你類似,那個打印出來的如果不展開第一次是沒有這個屬性,Console顯示的未必是最真實的。

2017年8月23日 07:14