RT
In addition to using native, are there any methods and techniques that come with Vue?
Thank you~
怪我咯2017-05-19 10:31:29
var el = document.getElementById('container-id');
el.addEventListener('click', function(e) {
var p = e.target.parentElement;
var index = Array.prototype.indexOf.call(p.children, e.target);
}
Just giving you an idea
<p class="container" ref="containBox">
<span @click="getIndex">test</span>
<span>test</span>
<span>test</span>
<span>test</span>
<span>test</span>
</p>
export default {
methods: {
getIndex (e) {
const parent = this.$refs.containBox.xxx
// 上面我忘记xxx是什么了,反正可以获取父元素,console.log(this.$refs)看看
const index = Array.prototype.indexOf.call(parent.children, e.target)
// ...
}
}
}
大家讲道理2017-05-19 10:31:29
Where does the index come from without a loop?? Where does the index refer to?
仅有的幸福2017-05-19 10:31:29
Use native document.queraySelectAlll to give li the same class name to get the li array. Now there is an index
巴扎黑2017-05-19 10:31:29
I don’t quite understand what you mean. . . .
How to load list data without using v-for? To find the node sequence number according to the dom, you must also have the dom node. . .