<body>
<p id="app">
<p class="con1" @click="click">
vue
<p class="con2"></p>
</p>
</p>
<script>
var vm = new Vue({
el: '#app',
mounted() {
for (let i of this.$el.children) {
console.log(i)
}
},
methods: {
click() {
for (let i = 0; i < this.$el.children.length; i++) {
console.log(this.$el.children[i])
}
}
}
})
</script>
</body>
It is obviously nested, but after generation it is the same level
This is followed by the
vue
没关系,是因为浏览器渲染的时候不允许<p>
标签包含<p>
标签,所以你自己看下,实际渲染生成了三个<p>
tag.Throw it aside
vue
and write a separate oneYou will also find that it is rendered by the browser as