怪我咯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);
}
只是提供个思路
<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)
// ...
}
}
}