logo
  • 教程列表
  • SO官方文档
  • 在 Vue 中使用它
    • 错误使用箭头函数定义引用此方法的方法
    • RIGHT 使用典型的函数语法定义方法
    • 错误在 Vue 方法内部的回调中使用它
    • 正确使用闭包来捕获它
    • 右使用箭头函数
    • 正确使用 bind
    • 错误在承诺中使用这个
  1. StackOverflow 文档
  2. Vue.js 教程
  3. 在 Vue 中使用它
  4. 错误在 Vue 方法内部的回调中使用它

错误在 Vue 方法内部的回调中使用它

Created: November-22, 2018

new Vue({
  el:"#app",
  data:{
    foo: "bar"
  },
  methods:{
    doSomethingAsynchronous(){
      setTimeout(function(){
        // This is wrong! Inside this function,
        // "this" refers to the window object.
        this.foo = "baz";
      }, 1000);
    }
  }
})
  • 正确使用闭包来捕获它
  • RIGHT 使用典型的函数语法定义方法

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明