zoukankan      html  css  js  c++  java
  • VUE中不能使用箭头函数的地方

    1.不应该使用箭头函数来定义一个生命周期方法
    2.不应该使用箭头函数来定义 method 函数
    3.不应该使用箭头函数来定义计算属性函数
    4.不应该对 data 属性使用箭头函数
    5.不应该使用箭头函数来定义 watcher 函数

    原因:
    箭头函数绑定了父级作用域的上下文,this 将不会按照期望指向 Vue 实例。
    也就是说,你不能使用this来访问你组件中的data数据以及method方法了。
    this将会指向undefined。经常导致 Uncaught TypeError: Cannot read property of undefined 或 Uncaught TypeError: this.myMethod is not a function 之类的错误

  • 相关阅读:
    跨域问题注解解决
    跳出循环到指定位置
    idea model管理
    maven 取本地jar
    注解 元注解
    手动打jar包到maven
    sonar搭建
    jmockit、junit
    注解
    虚拟机指令
  • 原文地址:https://www.cnblogs.com/smile-fanyin/p/15092947.html
Copyright © 2011-2022 走看看