掃二維碼與項(xiàng)目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
對于大多數(shù)單頁面應(yīng)用,都推薦使用官方支持的vue-router庫。更多細(xì)節(jié)可以看vue-router文檔。

如果只需要非常簡單的路由而不需要引入整個路由庫,可以動態(tài)渲染一個頁面級的組件像這樣:
const NotFound = { template: 'Page not found
' }
const Home = { template: 'home page
' }
const About = { template: 'about page
' }
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) }
})結(jié)合HTML5 History API,你可以建立一個非常基本但功能齊全的客戶端路由器??梢灾苯涌磳?shí)例應(yīng)用。
如果有非常喜歡的第三方路由,如Page.js或者 Director, 整合很簡單。 這有個用了Page.js的復(fù)雜示例。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流