Skip to content

Instantly share code, notes, and snippets.

@edwardkenfox
Created September 12, 2017 12:36
Show Gist options
  • Select an option

  • Save edwardkenfox/cecf9cebf7d3fcfd3acb52344d968b30 to your computer and use it in GitHub Desktop.

Select an option

Save edwardkenfox/cecf9cebf7d3fcfd3acb52344d968b30 to your computer and use it in GitHub Desktop.
Vue $refs order check
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<script src="https://unpkg.com/vue"></script>
</head>
<body>
<div id="app"></div>
<script>
const child = {
template: `<div class="child" v-text="index"></div>`,
props: {
index: { type: Number }
}
}
new Vue({
el: '#app',
components: {
child
},
template: `
<div class="parent">
<ul>
<li is="child" v-for="i in 10" :index="i" ref="children" key="i"></li>
</ul>
</div>
`,
mounted() {
this.$refs.children.map((child, ref_index) => {
console.log(`ref_index: ${ref_index}, child.index: ${child.index}`)
});
}
})
</script>
</body>
</html>
ref_index: 0, child.index: 1
ref_index: 1, child.index: 2
ref_index: 2, child.index: 3
ref_index: 3, child.index: 4
ref_index: 4, child.index: 5
ref_index: 5, child.index: 6
ref_index: 6, child.index: 7
ref_index: 7, child.index: 8
ref_index: 8, child.index: 9
ref_index: 9, child.index: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment