VUE---常用js方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Miracle_Gaaral/article/details/86618313

定时器:

this.timer = setTimeout(()=>{

    function()

}, 30ms)

自动播放时,需要clearTimeout(this.timer),然后重新计时

destroyed(){

    clearTimeout(this.timer)

}

监听窗口大小改变

window.addEventListener('resize', ()=>{

      function()

})

向数组中添加元素:   arr[]              arr.push()

向对象中添加元素:      obj={}         obj["key"]=value

vue中获取当前路由器的名称

this.routeName = this.$router.currentRoute.name

vue中返回到上一级

this.$router.back()

charCodeAt()          返回指定位置的字符的Unicode编码

substr(start, length)    截取字符串

parseInt()-------解析成整数

获取屏幕的宽度: window.innerWidth

获取某个元素的宽度:this.$refs.xxx.clientWidth

获取网页元素的位置: getBoundingClientRect() ,它返回一个对象,其中包含了left、right、top、bottom四个属性

向下取整:      interval = interval    |   0             当interval=12.22332时,得到结果为12

猜你喜欢

转载自blog.csdn.net/Miracle_Gaaral/article/details/86618313