wepy中methods调用methods,并且保证this指向一致

190 阅读1分钟

methods={ selectDistrict(e) { var that = this console.log('执行选择框中的this指向', that) // 在该方法中调用地区动画方法:如果该方法也写在methods中,它输出的this指的是selectDistrict,而不是最外层this // that.methods.startAddressAnimation(true)

    // 所以如果要保证this指向一致的话,将做以下调整:将被调用方法写在methods外部,
    that.startAddressAnimation()
  },

// startAddressAnimation(true){ // console.log('打印this', this) // }
};

startAddressAnimation(isSHow){ console.log('打印this', this) }