99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

Vue 3.0 路由

2021-07-16 11:44 更新

#官方 Router

對(duì)于大多數(shù)單頁(yè)面應(yīng)用,都推薦使用官方支持的 vue-router 庫(kù)。更多細(xì)節(jié)可以移步 vue-router 文檔。

#從零開(kāi)始簡(jiǎn)單的路由

如果你只需要非常簡(jiǎn)單的路由而不想引入一個(gè)功能完整的路由庫(kù),可以像這樣動(dòng)態(tài)渲染一個(gè)頁(yè)面級(jí)的組件:

const NotFoundComponent = { template: '<p>Page not found</p>' }
const HomeComponent = { template: '<p>Home page</p>' }
const AboutComponent = { template: '<p>About page</p>' }


const routes = {
  '/': HomeComponent,
  '/about': AboutComponent
}


const SimpleRouter = {
  data: () => ({
    currentRoute: window.location.pathname
  }),


  computed: {
    CurrentComponent() {
      return routes[this.currentRoute] || NotFoundComponent
    }
  },


  render() {
    return Vue.h(this.CurrentComponent)
  }
}


Vue.createApp(SimpleRouter).mount('#app')

結(jié)合 HTML5 History API,你可以建立一個(gè)麻雀雖小但是五臟俱全的客戶端路由器??梢灾苯涌?a rel="external nofollow" target="_blank" target="_blank" rel="nofollow">實(shí)例應(yīng)用。

#整合第三方路由

如果你有更偏愛(ài)的第三方路由,如 Page.js 或者 Director,整合起來(lái)也一樣簡(jiǎn)單。這里有一個(gè)使用了 Page.js 的完整示例。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)