javascript - Vue2.0 How to get the index in the event without v-for loop?
phpcn_u1582
phpcn_u1582 2017-05-19 10:29:29
0
4
544

RT

In addition to using native, are there any methods and techniques that come with Vue?
Thank you~

phpcn_u1582
phpcn_u1582

reply all (4)
刘奇
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


test test test test test

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) // ... } } }
    大家讲道理

    Where does the index come from without a loop?? Where does the index refer to?

      仅有的幸福

      Use native document.queraySelectAlll to give li the same class name to get the li array. Now there is an index

        巴扎黑

        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. . .

          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!