v-ref and v-for
Illustrate an issue on v-ref inside v-for loop in Vue.js 1.0.11
by Axel Haustant
HTML
<script src="https://rawgit.com/yyx990803/vue/v1.0.11/dist/vue.js"></script>
<div id="app">
<h2>Components</h2>
<comp v-for="item in items" v-ref:items :value="item"></comp>
<div v-for="item in items">
<comp v-ref:nested :value="item"></comp>
</div>
<h2>$refs.items</h2>
<p>content: {{ $refs.items }}</p>
<p>is Array: {{ $refs.items | isArray }}</p>
<p>typeof: {{ typeof $refs.items }}</p>
<h2>$refs.nested</h2>
<p>content: {{ $refs.nested }}</p>
<p>is Array: {{ $refs.nested | isArray }}</p>
<p>typeof: {{ typeof $refs.nested }}</p>
</div>
Babel + JSX
Vue.config.debug = true;
new Vue({
el: '#app',
data() {
return {
items: [1, 2]
};
},
components: {
comp: {
template: '<div>{{value}}</div>',
props: ['value']
}
},
filters: {
isArray(value) {
return Array.isArray(value);
}
}
});