内部函数中的this指向 它的直接调用者
箭头函数中的this指向 它的外层调用者
<script>
var app = new Vue({
el:'#app',
data:{
message:"你好!111",
roleArr :[]
},
methods: {
getAll:function () {
alert("!!!")
that = this //调用传递
axios.get("http://localhost:8080/roles").then((Result) =>{
console.log(Result)
for (var role of Result.data.data) {
this.roleArr.push(role)
}
}),function (err) {
console.log(err)
}
}
}
})
</script>