1. 程式人生 > >vue-router-1-安裝與基本使用

vue-router-1-安裝與基本使用

基本 一個 https 基本使用 註入 out git const tps

npm install vue-router
import Vue from vue
import VueRouter from vue-router

Vue.use(VueRouter)
//使用最新的開發版
git clone https://github.com/vuejs/vue-router.git node_modules/vue-router
cd node_modules/vue-router
npm install
npm run build
 <div id="app">
  <!-- <router-link> 默認會被渲染成一個 `<a>` 標簽 --> <router-link
to="/foo">Go to Foo</router-link>    <!-- 路由匹配到的組件將渲染在這裏 --> <router-view></router-view>
</div>
// 1. 定義(路由)組件,可以 import 進來
const Foo = { template: <div>foo</div> }

// 2. 定義路由
const routes = [
  { path: /foo, component: Foo },
]

// 3. 創建 router 實例,然後傳 `routes` 配置
const router = new VueRouter({ routes // (縮寫)相當於 routes: routes }) // 4. 創建和掛載根實例,通過 router 配置參數註入路由, const app = new Vue({ router }).$mount(‘#app‘)

vue-router-1-安裝與基本使用