我这样试了一下:
App.vue
:
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
})
}
}
Todos.vue
export default {
props: ['initialTodos'],
data() {
return {
todos: this.initialTodos ? [].concat(this.initialTodos) : [],
newTodo: { title: '', completed: false }
}
},
Todos.vue
组件显示的是 {title: '123', completed: true}
。
好像 axios 请求回调里的赋值
mounted() {
this.axios.get('http://homestead.app/api/todos').then((response) => {
console.log(response.data)
this.initialTodos = response.data
})
}
并没导致 Todos
组件的重绘。