首页 > 其他 > 详细

Vue路由机制

时间:2017-11-13 15:24:08      阅读:247      评论:0      收藏:0      [点我收藏+]

 

视图层:

主要是<router-link>和<router-view>两个标签

<router-link>执行时会转换成<a>,并根据自己的to属性将路由地址转变成href的值,然后渲染在<router-view>标签中。

 

js配置路由的两种写法

写法一:

index.js

Vue.use(Router)

export default new Router({
  routes: [
    {path:‘/‘,component:Home},
    {path:‘/detail‘,component:detail}
  ]
})

main.js

import router from ‘./router/index.js‘

new Vue({
  router,
  render: h => h(App)
}).$mount(‘#app-box‘)

 

写法二:

main.js

import Home from ‘xxx‘
import detail from ‘xxx‘

Vue.use(VueRouter)

const routes = [{  //定义路由表
  path: ‘/‘,
  component: Home
},{
  path: ‘/detail‘,
  component: detail
}]

const router = new VueRouter({创建router管理上面定义好的routes
  routes
})

new Vue({    //将配置好的router注入Vue根实例中
  router,
  render: h => h(App)
}).$mount(‘#app-box‘)

 

Vue路由机制

原文:http://www.cnblogs.com/Dengxiaobo/p/7826110.html

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