首页 > 其他 > 详细

vue-router-1-安装与基本使用

时间:2017-10-09 19:28:03      阅读:325      评论:0      收藏:0      [点我收藏+]
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-安装与基本使用

原文:http://www.cnblogs.com/avidya/p/7642537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!