函数中:此时函数中的this表示全局对象window
function add(){
this
}
对象下函数中:this表示thiss对象
var thiss = {
function add(){
this
}
}
vue组件中:组件或者实例中,不管是生命周期钩子函数created还是自定义函数plus,他们中的this都是指当前vue实例
new Vue({
data: {
add: 1
},
created: function () {
console.log('add is: ' + this.add)
}
methods: {
plus: function () {
this.add++
}
}
})
回调函数中:此时回调函数function(resuat, kill)会重新将this指向匿名对象(类比java的匿名类),所以其中的this指代父级组件,执行this.buscarLojas
会报错找不到函数
methods: {
searchLocations: function() {
var address = thi