vue中this.$el 和 this.$ref

+    
    +
  • {{el.value}}
  • +

vue中也是允许进行dome操作的(但是不建议)


这里我就说说 this.$el和this.$ref的区别



this.$el是在mounted中才会出现的,在created的时候是没有的所以我们引用的时候

 mounted () {
 +      /* 事件绑定 */
 +      this.$el.addEventListener('touchstart', this.itemTouchStart)
 +      this.$el.addEventListener('touchmove', this.itemTouchMove)
 +      this.$el.addEventListener('touchend', this.itemTouchEnd)


它指的是当前组件的的元素


this.$ref

点击打开链接


+    
    +
  • {{el.value}}
  • +



+      setWheelDeg (updateDeg, type, time = 1000) {
 +        if (type === 'end') {
 +          this.$refs.wheel.style.webkitTransition = `transform ${time}ms cubic-bezier(0.19, 1, 0.22, 1)`
 +          this.$refs.wheel.style.webkitTransform = `rotate3d(1, 0, 0, ${updateDeg}deg)`
 +        } else {
 +          this.$refs.wheel.style.webkitTransition = ''
 +          this.$refs.wheel.style.webkitTransform = `rotate3d(1, 0, 0, ${updateDeg}deg)`
 +        }
 +      },



你可能感兴趣的:(vue)