Vue
Vue第四天路由官方路由从零开始简单的路由
Vue第四天
路由
官方路由
对于大多数单页面应用,都推荐使用官方支持的 vue-router 库。更多细节可以移步 vue-router 文档。
从零开始简单的路由
const NotFound
= { template
: '<p>Page not found</p>' }
const Home
= { template
: '<p>home page</p>' }
const About
= { template
: '<p>about page</p>' }
const routes
= {
'/': Home
,
'/about': About
}
new Vue({
el
: '#app',
data
: {
currentRoute
: window
.location
.pathname
},
computed
: {
ViewComponent () {
return routes
[this.currentRoute
] || NotFound
}
},
render (h
) { return h(this.ViewComponent
) }
})
转载请注明原文地址:https://blackberry.8miu.com/read-13287.html