$refs
参考:
子コンポーネントインスタンスと子要素へのアクセス | Vue.js [公式]
そうか、要素に触るなら $refs と mounted を組み合わせれば良いのか。| Ginpen.com
v-for で ref を使うと $refs での参照が配列になる
参考:
子コンポーネントインスタンスと子要素へのアクセス | Vue.js [公式]
VueJs getting an element within a component – Stack Overflow
$refs はリアクティブではない
$refs are only populated after the component has been rendered, and it is not reactive.
Solution
for the example @Kingwl https://jsfiddle.net/z11fe07p/773/, i found a solution https://jsfiddle.net/Fmajor/cuay7v1j/2/
just manually clear the old ref array to null, and it works
this.$nextTick
For the problem of $refs not being reactive, I’m using this.$nextTick(function () { }) and it works, I get an updated list of $refs.
Correct approach to get the correct index
The correct approach to get the correct index is just as @adamawang proposed:
Bind index to dom as :data-index=”index” and then access it via parseInt(el.dataset.index) when using $refs
参考:
alekzonder/1zcLkuwq – JSFiddle
$children
参考:
Accessing array of components via $refs? – Vue Forum
$slots
参考:
Support ref attribute in slots · Issue #7661 · vuejs/vue – GitHub
$root
参考: