@JellyBool 我在 App.vue
中给 mounted
方法中给 this.initialTodos
赋值并没起作用。
下面这样可以给组件初始化 todo 列表。
export default {
name: 'app',
components: {
Todos
},
data() {
return {
initialTodos: [
{title: '123', completed: true},
],
}
},
mounted() {
this.axios.get('http://homestead.app/api/todos').then((response) => {
console.log(response.data)
//this.initialTodos = response.data
})
}
}
</script>
但这样的话,todo 列表为空。
export default {
name: 'app',
components: {
Todos
},
data() {
return {
initialTodos: [
// {title: '123', completed: true},
],
}
},
mounted() {
this.axios.get('http://homestead.app/api/todos').then((response) => {
console.log(response.data)
this.initialTodos = response.data
})
}
}
</script>
并且后台数据能正常拿到。这是后台 API。
Route::get('/todos', function (Request $request) {
return [
[ 'title' => '吃早饭', 'completed' => false ],
[ 'title' => '吃午饭', 'completed' => false ],
[ 'title' => '吃晚饭', 'completed' => false ],
];
});