Vuejs技术栈--路由

页面跳转--路由vue-router

router/index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../pages/Login/Login.vue'
// 声明使用插件
Vue.use(VueRouter)

export default new VueRouter({
  // 所有路由
  routes: [
    {
      path: '/msite',
      component: Login, 
      meta: {
        showFooter: true
      }
    },
    ...
    ]
})

main.js

import Vue from 'vue'
import app from './app'
import router from './router'

new Vue({
el: '#app',
render: h => h(app),
router,
})

<router-link to="/"><router-link>

<router-view></router-view>

this.$router.push(path);写入历史记录

this.$router.replace(path);

传参

:to="{name='路由名称',params:{key:value}}"

this.$router.push({name:‘路由名字’},params:{key:value})

 

子路由

//路由关系
{ path:
'/shop', component: Shop, children: [ { path: '/shop/goods', component: ShopGoods }, { path: '/shop/ratings', component: ShopRatings }, { path: '/shop/info', component: ShopInfo }, { path: '', redirect: '/shop/goods' }, ] }
<template>
<div>
<ShopHeader/>
<div class="tab">
<div class="tab-item">
<router-link to="/shop/goods" replace>点餐</router-link>
</div>
<div class="tab-item">
<router-link to="/shop/ratings" replace>评价</router-link>
</div>
<div class="tab-item">
<router-link to="/shop/info" replace>商家</router-link>
</div>
</div>
<router-view/>
</div>
</template>
View Code

 

多视图(命名区分)

<router-view name="sidebar"></router-view>

<router-view name="content"></router-view>

components:{

  sidebar:组件..

  content:组件..

}

转载于:https://www.cnblogs.com/xiaohuai/p/9169318.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值