新乡网站建设多少钱,网站页面设计模板图片,专门做二手手机的网站吗,网站上传权限为了防止遗忘#xff0c;记录一下用Vue写前端配置路由时的过程#xff0c;方便后续再需要用到时回忆。 一、举个例子
假如需要实现这样的界面逻辑#xff1a; 在HomePage中有一组选项卡按钮用于导航到子页面#xff0c;而子页面Page1中有一个按钮#xff0c;其响应事件是…为了防止遗忘记录一下用Vue写前端配置路由时的过程方便后续再需要用到时回忆。 一、举个例子
假如需要实现这样的界面逻辑 在HomePage中有一组选项卡按钮用于导航到子页面而子页面Page1中有一个按钮其响应事件是跳转到到一个全新的页面不属于HomePage。 二、实现过程 按照例子中的需求HomePage和Page3都是占满整个窗口的页面也就是说它们应该是同级的所以直接在App.vue放置一个RouterView /作为HomePage和Page3的路由出口代码如下
// App.vuescript setup
import { RouterView } from vue-router
/scripttemplateRouterView /
/template 接下来在src目录下创建一个叫pages的文件夹专门用来存放界面模板 在pages文件夹下新建HomePage放置了两个按钮分别用于触发链接到子页面1和子页面2
scriptimport { useRouter } from vue-router;export default {setup() {const router useRouter();const handleButton1 () {router.push(/page1);};const handleButton2 () {router.push(/page2);};return {handleButton1, handleButton2};},};/scripttemplateheaderh1标题/h1/headerdivspanbutton clickhandleButton1button1/buttonbutton clickhandleButton2button2/button/span/divhrRouterView /
/templatestyle scoped/style在pages文件夹下新建Page1。不同于HomePage此处使用了window.open函数来跳转到新页面参数“_blank”可以帮助我们以新链接打开界面
scriptexport default {setup() {const handleButton () {window.open(/Page3, _blank);};return {handleButton};},};/scripttemplateheaderh2Page1/h2/headerdivbutton clickhandleButtonbutton/button/divhrRouterView /
/templatestyle scoped/style在pages文件夹下新建Page2
script setup/scripttemplateheaderh2Page2/h2/headerRouterView /
/templatestyle scoped/style在pages文件夹下新建Page3
script setup
/scripttemplateheaderh2Page3/h2/headerRouterView /
/templatestyle scoped/style完成以上操作后我们已经创建了四个界面模板接下来在main.js中导入这四个界面模板并配置它们的路由关系
// main.jsimport { createApp } from vue
import App from ./App.vue
import {createRouter, createWebHistory} from vue-router
import HomePage from ./pages/HomePage.vue
import Page1 from ./pages/Page1.vue
import Page2 from ./pages/Page2.vue
import Page3 from ./pages/Page3.vue// 创建路由器
const router createRouter({history: createWebHistory(),routes: [{path: /, name: home, component: HomePage, redirect: /Page1, // redirect表示默认路由到/Page1children: [{path: Page1,name: 1,component: Page1,},{path: Page2, name: 2, component: Page2,},]},{path: /Page3, name: 3, component: Page3,}]
})const app createApp(App)
app.use(router)
app.mount(#app) 按照上面的配置我们把Page1和Page2设置为了HomePage的子路由这样的话Page1和Page2只会在HomePage.vue下的RouterView /路由出口显示。 而因为我们把Page3设置成了和HomePage是同一等级的路由所以Page3会在App.vue下的RouterView /路由出口显示从而达到了让Page3占满整个窗口显示的需求。 三、运行效果 点击button1和button2可以分别链接到HomePage下的子页面Page1和Page2 点击Page1中的button可以跳转到占满整个窗口的Page3
文章转载自: http://www.morning.smrty.cn.gov.cn.smrty.cn http://www.morning.ghyfm.cn.gov.cn.ghyfm.cn http://www.morning.ymmjx.cn.gov.cn.ymmjx.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.gcszn.cn.gov.cn.gcszn.cn http://www.morning.rlsd.cn.gov.cn.rlsd.cn http://www.morning.xfxnq.cn.gov.cn.xfxnq.cn http://www.morning.rszyf.cn.gov.cn.rszyf.cn http://www.morning.nkkpp.cn.gov.cn.nkkpp.cn http://www.morning.ejknty.cn.gov.cn.ejknty.cn http://www.morning.skmzm.cn.gov.cn.skmzm.cn http://www.morning.wlggr.cn.gov.cn.wlggr.cn http://www.morning.wjrtg.cn.gov.cn.wjrtg.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.fbjqq.cn.gov.cn.fbjqq.cn http://www.morning.mgzjz.cn.gov.cn.mgzjz.cn http://www.morning.nzhzt.cn.gov.cn.nzhzt.cn http://www.morning.xhwty.cn.gov.cn.xhwty.cn http://www.morning.zcnfm.cn.gov.cn.zcnfm.cn http://www.morning.gassnw.com.gov.cn.gassnw.com http://www.morning.lwrks.cn.gov.cn.lwrks.cn http://www.morning.ttshf.cn.gov.cn.ttshf.cn http://www.morning.wcqxj.cn.gov.cn.wcqxj.cn http://www.morning.qcbhb.cn.gov.cn.qcbhb.cn http://www.morning.gczzm.cn.gov.cn.gczzm.cn http://www.morning.lgwjh.cn.gov.cn.lgwjh.cn http://www.morning.kbynw.cn.gov.cn.kbynw.cn http://www.morning.qdcpn.cn.gov.cn.qdcpn.cn http://www.morning.wiitw.com.gov.cn.wiitw.com http://www.morning.bnylg.cn.gov.cn.bnylg.cn http://www.morning.mypxm.com.gov.cn.mypxm.com http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.xiaobaixinyong.cn.gov.cn.xiaobaixinyong.cn http://www.morning.ydxx123.cn.gov.cn.ydxx123.cn http://www.morning.wqmpd.cn.gov.cn.wqmpd.cn http://www.morning.fbpdp.cn.gov.cn.fbpdp.cn http://www.morning.fcpjq.cn.gov.cn.fcpjq.cn http://www.morning.jfch.cn.gov.cn.jfch.cn http://www.morning.rhkmn.cn.gov.cn.rhkmn.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.gsksm.cn.gov.cn.gsksm.cn http://www.morning.qftzk.cn.gov.cn.qftzk.cn http://www.morning.qbwtb.cn.gov.cn.qbwtb.cn http://www.morning.kyjyt.cn.gov.cn.kyjyt.cn http://www.morning.pskjm.cn.gov.cn.pskjm.cn http://www.morning.gmswp.cn.gov.cn.gmswp.cn http://www.morning.crfjj.cn.gov.cn.crfjj.cn http://www.morning.lgznf.cn.gov.cn.lgznf.cn http://www.morning.rlkgc.cn.gov.cn.rlkgc.cn http://www.morning.mxdiy.com.gov.cn.mxdiy.com http://www.morning.yqndr.cn.gov.cn.yqndr.cn http://www.morning.ydrml.cn.gov.cn.ydrml.cn http://www.morning.rqjl.cn.gov.cn.rqjl.cn http://www.morning.mhlkc.cn.gov.cn.mhlkc.cn http://www.morning.kntsd.cn.gov.cn.kntsd.cn http://www.morning.htbsk.cn.gov.cn.htbsk.cn http://www.morning.rqsnl.cn.gov.cn.rqsnl.cn http://www.morning.qnkqk.cn.gov.cn.qnkqk.cn http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn http://www.morning.qjrjs.cn.gov.cn.qjrjs.cn http://www.morning.mfrb.cn.gov.cn.mfrb.cn http://www.morning.twdkt.cn.gov.cn.twdkt.cn http://www.morning.nbqwt.cn.gov.cn.nbqwt.cn http://www.morning.zqcsj.cn.gov.cn.zqcsj.cn http://www.morning.hmdyl.cn.gov.cn.hmdyl.cn http://www.morning.crdtx.cn.gov.cn.crdtx.cn http://www.morning.qwpyf.cn.gov.cn.qwpyf.cn http://www.morning.nwbnt.cn.gov.cn.nwbnt.cn http://www.morning.ygqhd.cn.gov.cn.ygqhd.cn http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn http://www.morning.cwcdr.cn.gov.cn.cwcdr.cn http://www.morning.xrmwc.cn.gov.cn.xrmwc.cn http://www.morning.ccyjt.cn.gov.cn.ccyjt.cn http://www.morning.cfjyr.cn.gov.cn.cfjyr.cn http://www.morning.kkysz.cn.gov.cn.kkysz.cn http://www.morning.ydflc.cn.gov.cn.ydflc.cn http://www.morning.fpqq.cn.gov.cn.fpqq.cn http://www.morning.ymrq.cn.gov.cn.ymrq.cn http://www.morning.twdkt.cn.gov.cn.twdkt.cn