所以这是我的代码
var portal = new Vue({
el: "#AnnounceController",
data: {
ann: {
id: '',
content: ''
},
announces: [],
success: false,
edit: false
},
methods: {
fetchAnnounce: function () {
axios.get('/api/announces')
.then(function (response) {
this.announces = response.data;
console.log(this.announces);
})
.catch(function (error) {
console.log(error);
});
}
},
computed: {},
mounted: function () {
console.log('mounted')
this.fetchAnnounce()
}
我通过axios向基于laravel的api发出GET请求,当我看到来自axios的响应时,我确实看到了我的数据,当我尝试将这些数据分配给'宣布'从数据来看,它不起作用。 Vue-devtools显示我的数据并宣布'属性为空,this.announces的日志显示我的数据,不知何故像vue实例的数据属性和this.announces不同。
答案 0 :(得分:0)
fetchAnnounce: function () {
axios.get('/api/announces')
.then(function (response) {
this.announces = response.data;
console.log(this.announces);
}.bind(this))
.catch(function (error) {
console.log(error);
});
}