当前位置: 移动技术网 > IT编程>脚本编程>vue.js > Vue.js 单页面多路由区域操作的实例详解

Vue.js 单页面多路由区域操作的实例详解

2017年12月12日  | 移动技术网IT编程  | 我要评论

i5 3230m,18612665609,召唤狂想

单页面多路由区域操作

在一个页面中有两个及以上的<router-view>区域,需要通过设置路由的index.js,来操作这些区域的内容

app.vue 中设置:

<router-view></router-view>
<router-view name="left" style="float: left;width: 50%; height: 300px;background-color: #ccc;"></router-view>
<router-view name="right" style="float: left;width: 50%; height: 300px;background-color: #898;"></router-view>

index.js中设置:

import vue from 'vue'
import router from 'vue-router'
import hello from '@/components/hello'
import first1 from '@/components/first1'
import first2 from '@/components/first2'

vue.use(router)

export default new router ({
 routes : [
  {
   path : '/',
   name : 'hello',
   components : {
    default : hello,
    left : first1,
    right : first2
   }
  }
 ]
})

下面的设置是当url为/#/first 时,交换两个组件显示的位置

export default new router ({
 routes : [
  {
   path : '/',
   name : 'hello',
   components : {
    default : hello,
    left : first1,
    right : first2
   }
  }, {
   path : '/first',
   name : 'first',
   components : {
    default : hello,
    left : first2,
    right : first1
   }   
  }
 ]
})

以上就是 vue.js 单页面多路由区域操作,如有疑问请大家留言,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网