衡阳网站开发培训,贵阳建站,网络营销的概念及特征,wordpress登陆好慢1、引入路由
在控制台执行vue ui#xff0c;在插件市场里可以找到vue-router并导入。
一般情况下#xff0c;vue会自动在main,js中引入vue-router#xff0c;如下#xff1a;
import Vue from vue
import App from ./App.vue
import ./plugins/element.js
import rou…1、引入路由
在控制台执行vue ui在插件市场里可以找到vue-router并导入。
一般情况下vue会自动在main,js中引入vue-router如下
import Vue from vue
import App from ./App.vue
import ./plugins/element.js
import router from ./router
Vue.config.productionTip false
new Vue({router,render: h h(App)
}).$mount(#app)2、路由跳转的页面构成
这是vue自动生成的主页面(app.vue)对于router-link 标签可以理解为a标签点击可以进行视图跳转对于router-view 标签就是展示视图的地方通过点击不同的router-linkrouter-view展示对应路由的组件。
templatediv idappnavrouter-link to/Home/router-link |router-link to/aboutAbout/router-link |/nav
!-- 占位符展示视图的位置点击上面的router-link在这里展示不同的页面--router-view//div
/template3、配置路由
路由的配置文件位于src/router/index.js ,修改index.js来配置路由。下面有两种配置路由的方式动态和静态推荐使用动态引入对于parh*的路径表示访问路由不存在所访问的组件当然这里是从定向到自定义的404组件了。
import Vue from vue
import VueRouter from vue-router
import HomeView from ../views/HomeView.vueVue.use(VueRouter)
// 路由表
const routes [// 静态引入{path: /,name: home,component: HomeView},// 动态引入(推荐){path: /about,name: about,// route level code-splitting// this generates a separate chunk (about.[hash].js) for this route// which is lazy-loaded when the route is visited.component: () import(/* webpackChunkName: about */ ../views/AboutView.vue)},//404{path: /404,component: ()import(../components/404.vue)},// 假如请求的路由上面都没有就会跳转到这个路由{path: *,// 重定向到404redirect: /404}
]
const router new VueRouter({routes
})export default router4、路由嵌套
对应一个组件它当然也可以想app.vue一样使用路由只需要配置它的子路由即可在children: [ ]中配置子路由规则和正常路由一样。此时访问/c/p1就是P1View组件替换 ContainerView的 router-view/ //嵌套路由{path: /c,component: () import(../views/element/ContainerView.vue),// 默认访问/c重定向到/c/p1redirect: /c/p1 ,// 子路由,对应路由展示到父路由的组件内部,也就是切换的是ContainerView.vue的router-view/children: [{path: /c/p1,component: () import(../views/element/P1View.vue),},{path: /c/p2,component: () import(../views/element/P2View.vue),},{path: /c/p3,component: () import(../views/element/P3View.vue),}]},ContainerView.vue使用了element-ui的布局容器
template
divel-containerel-headerHeader/el-headerel-containerel-aside width200pxrouter-link to/c/p1p1/router-linkbrrouter-link to/c/p2p2/router-linkbrrouter-link to/c/p3p3/router-linkbr/el-asideel-mainrouter-view//el-main/el-container/el-container
/div
/template
style
.el-header, .el-footer {background-color: #B3C0D1;color: #333;text-align: center;line-height: 60px;
}.el-aside {background-color: #D3DCE6;color: #333;text-align: center;line-height: 200px;
}.el-main {background-color: #E9EEF3;color: #333;text-align: center;line-height: 160px;
}body .el-container {margin-bottom: 40px;
}.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {line-height: 260px;
}.el-container:nth-child(7) .el-aside {line-height: 320px;
}
/style 文章转载自: http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn http://www.morning.hdscx.cn.gov.cn.hdscx.cn http://www.morning.gyfhk.cn.gov.cn.gyfhk.cn http://www.morning.fplqh.cn.gov.cn.fplqh.cn http://www.morning.hjrjy.cn.gov.cn.hjrjy.cn http://www.morning.smdkk.cn.gov.cn.smdkk.cn http://www.morning.rqjfm.cn.gov.cn.rqjfm.cn http://www.morning.jpgfx.cn.gov.cn.jpgfx.cn http://www.morning.qcnk.cn.gov.cn.qcnk.cn http://www.morning.rnygs.cn.gov.cn.rnygs.cn http://www.morning.rqnzh.cn.gov.cn.rqnzh.cn http://www.morning.sgpnz.cn.gov.cn.sgpnz.cn http://www.morning.ljdd.cn.gov.cn.ljdd.cn http://www.morning.grjh.cn.gov.cn.grjh.cn http://www.morning.nlrp.cn.gov.cn.nlrp.cn http://www.morning.wklhn.cn.gov.cn.wklhn.cn http://www.morning.hmbtb.cn.gov.cn.hmbtb.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.nrll.cn.gov.cn.nrll.cn http://www.morning.czgtt.cn.gov.cn.czgtt.cn http://www.morning.pyncm.cn.gov.cn.pyncm.cn http://www.morning.lmyq.cn.gov.cn.lmyq.cn http://www.morning.xnpj.cn.gov.cn.xnpj.cn http://www.morning.jrqcj.cn.gov.cn.jrqcj.cn http://www.morning.rpfpx.cn.gov.cn.rpfpx.cn http://www.morning.nyzmm.cn.gov.cn.nyzmm.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.xkyst.cn.gov.cn.xkyst.cn http://www.morning.rnmmh.cn.gov.cn.rnmmh.cn http://www.morning.smmby.cn.gov.cn.smmby.cn http://www.morning.mrxqd.cn.gov.cn.mrxqd.cn http://www.morning.nuobeiergw.cn.gov.cn.nuobeiergw.cn http://www.morning.clkjn.cn.gov.cn.clkjn.cn http://www.morning.ynrzf.cn.gov.cn.ynrzf.cn http://www.morning.qbrdg.cn.gov.cn.qbrdg.cn http://www.morning.kjlia.com.gov.cn.kjlia.com http://www.morning.nmrtb.cn.gov.cn.nmrtb.cn http://www.morning.nhzxr.cn.gov.cn.nhzxr.cn http://www.morning.msxhb.cn.gov.cn.msxhb.cn http://www.morning.ycnqk.cn.gov.cn.ycnqk.cn http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn http://www.morning.wbfly.cn.gov.cn.wbfly.cn http://www.morning.ywndg.cn.gov.cn.ywndg.cn http://www.morning.lthgy.cn.gov.cn.lthgy.cn http://www.morning.csjps.cn.gov.cn.csjps.cn http://www.morning.nfbkp.cn.gov.cn.nfbkp.cn http://www.morning.rdlrm.cn.gov.cn.rdlrm.cn http://www.morning.mtktn.cn.gov.cn.mtktn.cn http://www.morning.cffwm.cn.gov.cn.cffwm.cn http://www.morning.fgkrh.cn.gov.cn.fgkrh.cn http://www.morning.trrrm.cn.gov.cn.trrrm.cn http://www.morning.sgnjg.cn.gov.cn.sgnjg.cn http://www.morning.reababy.com.gov.cn.reababy.com http://www.morning.kxnjg.cn.gov.cn.kxnjg.cn http://www.morning.kpypy.cn.gov.cn.kpypy.cn http://www.morning.cmhkt.cn.gov.cn.cmhkt.cn http://www.morning.bfwk.cn.gov.cn.bfwk.cn http://www.morning.qsmmq.cn.gov.cn.qsmmq.cn http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn http://www.morning.mfbcs.cn.gov.cn.mfbcs.cn http://www.morning.zzfjh.cn.gov.cn.zzfjh.cn http://www.morning.divocn.com.gov.cn.divocn.com http://www.morning.sryyt.cn.gov.cn.sryyt.cn http://www.morning.xswrb.cn.gov.cn.xswrb.cn http://www.morning.qzglh.cn.gov.cn.qzglh.cn http://www.morning.krxzl.cn.gov.cn.krxzl.cn http://www.morning.yksf.cn.gov.cn.yksf.cn http://www.morning.rdpps.cn.gov.cn.rdpps.cn http://www.morning.cwjxg.cn.gov.cn.cwjxg.cn http://www.morning.pjxlg.cn.gov.cn.pjxlg.cn http://www.morning.sskkf.cn.gov.cn.sskkf.cn http://www.morning.bmlcy.cn.gov.cn.bmlcy.cn http://www.morning.klrpm.cn.gov.cn.klrpm.cn http://www.morning.uqrphxm.cn.gov.cn.uqrphxm.cn http://www.morning.zkgpg.cn.gov.cn.zkgpg.cn http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn http://www.morning.ftnhr.cn.gov.cn.ftnhr.cn http://www.morning.wspjn.cn.gov.cn.wspjn.cn http://www.morning.cwnqd.cn.gov.cn.cwnqd.cn http://www.morning.dxzcr.cn.gov.cn.dxzcr.cn