route: {
data ({ to }) {
// This is the route data hook. It gets called every time the route
// changes while this component is active.
//
// What we are doing:
//
// 1. Get the `to` route using ES2015 argument destructuring;
// 2. Get the `page` param and cast it to a Number;
// 3. Fetch the items from the store, which returns a Promise containing
// the fetched items;
// 4. Chain the Promise and return the final data for the component.
// Note we are waiting until the items are resolved before resolving
// the entire object, because we don't want to update the page before
// the items are fetched.
const page = +to.params.page
document.title = 'Vue.js HN Clone'
return store.fetchItemsByPage(page).then(items => ({
page,
items
}))
}
},
上面是 vue-hackernews 中的一段代码,文档中没找到这种用法,求大神解读一下。
Vue Router 2版本已移除,详见
https://cn.vuejs.org/v2/guide...