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

  • 關於本站
  • 免責聲明