javascript - vue 怎么获取元素?

查看:119
本文介绍了javascript - vue 怎么获取元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

//报名数的滚动

        var box = document.querySelector('.list-box'),
            boxUl = document.querySelector('.list-box .list-ul'),
            boxLi = document.querySelectorAll('.list-ul li'),
            startX = 0,
            startTime, endTime, moveTime,
            startY = 0,
            moveDistance = 0;
        offLeft = 0;
      console.log(boxLi[0].offsetWidth);
      alert(boxLi[0])
        box.style.width = boxLi[0].offsetWidth * 4 + 'px';
         
        boxUl.style.width =boxLi[0].offsetWidth * boxLi.length + 'px';
       
        var moveWidth = boxUl.offsetWidth - box.offsetWidth;
        
        这上面是一个代码片段,页面是用vue2.0 来做的,boxLi里的li 是 v-for 循环出来的,boxLi[0]怎么都获取不到li,  在vue mounted 这里面执行也不行,最后我用winod.onload 还是无法获致到, 求解决方向法,怎么才能在 vue里获到元素操作???

解决方案

v-ref: dom

this.$refs.dom

这篇关于javascript - vue 怎么获取元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆