kenberkeley / vue-demo

Vue.js 示例项目 · 简易留言板。本项目拥有完善的文档说明与注释,让您快速上手 Vue.js 开发 SPA。Webpack / ES6 + Babel / Vue Router / (Vue Resource?) / (Vue Validator?) / (Vuex?) —— An Excellent Vue Starter with Best Practice / 最佳实践
https://kenberkeley.github.io/vue-demo/dist
Apache License 2.0
1.29k stars 410 forks source link

关于Vue 组件中route 何时执行。 #25

Closed souse closed 7 years ago

souse commented 7 years ago

在demo中看到一段代码如下:

export default { mixins: [updateQuery], components: { Pagination, LimitSelect, AuthorSelect, OptBtnGroup }, data: () => ({ total: 0, msgs: [] }), route: { data () { msgService .fetchList(this.$route.query) .then(({ total, rows }) => { this.total = total this.msgs = rows }) } },

请教下 route什么时候执行呢, 可以用生命周期的其他方法替换在route里给data重新赋值吗?

kenberkeley commented 7 years ago

https://github.com/vuejs/vue-router/blob/1.0/docs/zh-cn/pipeline/data.md