【发布时间】:2019-07-19 14:31:31
【问题描述】:
我正在尝试从 Laravel Vue 组件中的 API 获取数据。 我在控制台中收到此错误:
TypeError: 无法设置未定义的属性“大陆”
我错过了什么?
这是我的代码:
<script>
export default {
mounted() {
console.log('Component mounted.');
},
created(){
this.loadData();
},
data() {
return {
continents: [],
}
},
methods: {
loadData: function() {
axios.get('/api/continents')
.then(function (response) {
// handle success
console.log(response.data);
this.continents = response.data;
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
},
},
}
</script>
【问题讨论】: