新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)VUE2教程:Vue.js 2.0 路由
Vue.js 2.0 官方路由
對于大多數(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,你可以建立一個非?;镜δ荦R全的客戶端路由器??梢灾苯涌磳嵗龖?yīng)用。
整合第三方路由
如果有非常喜歡的第三方路由,如Page.js或者 Director, 整合很簡單。 這有個用了Page.js的復(fù)雜示例。
分享題目:創(chuàng)新互聯(lián)VUE2教程:Vue.js 2.0 路由
鏈接分享:http://www.dlmjj.cn/article/dphssgp.html


咨詢
建站咨詢
