国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

vue 基于abstract 路由模式 實現(xiàn)頁面內(nèi)嵌的示例代碼

瀏覽:2日期:2022-10-19 15:42:12
abstract 路由模式

abstract 是vue路由中的第三種模式,本身是用來在不支持瀏覽器API的環(huán)境中,充當fallback,而不論是hash還是history模式都會對瀏覽器上的url產(chǎn)生作用,本文要實現(xiàn)的功能就是在已存在的路由頁面中內(nèi)嵌其他的路由頁面,而保持在瀏覽器當中依舊顯示當前頁面的路由path,這就利用到了abstract這種與瀏覽器分離的路由模式。

路由示例

export const routes = [ { path: '/', redirect: 'abstract-route', }, { path: '/embed-route', name: 'embedded', component: () => import(/* webpackChunkName: 'embed' */ '../views/embed.vue'), }, { path: '/abstract-route', name: 'abstract', component: () => import(/* webpackChunkName: 'abstract' */ '../views/abstract.vue'), },];const router = new VueRouter({ mode: 'history', base: process.env.BASE_URL, routes,});

本次示例有兩個路由,分別為abstract,embedded,其中abstract視圖上展開一個抽屜,抽屜當中顯示embedded的視圖。即:

<template> <div> <RouterDrawer :visible.sync='visible' :path='{ name: ’embedded’ }' size='50%' ></RouterDrawer> <el-button @click='visible = true'>open drawer</el-button> </div></template>// embedded views<template> <div> embedded views </div></template>

vue 基于abstract 路由模式 實現(xiàn)頁面內(nèi)嵌的示例代碼

router-drawer 封裝

當前項目默認是history 的路由模式,因此在進入abstract頁面時,瀏覽器Url為http://127.0.0.1:8010/abstract-route,而router-drawer要做的是在此基礎(chǔ)上,重新實例化一個abstract模式的路由,然后在組件當中利用<router-view />去掛載要被內(nèi)嵌的目標頁面。即:

<template> <el-drawer :visible.sync='visible' v-bind='$attrs' :before-close='handleClose' > <router-view /> </el-drawer></template><script>import { routes } from '../router/index';import VueRouter from 'vue-router';export default { name: 'router-drawer', props: { path: { type: Object, required: true, }, visible: { type: Boolean, required: true, default: false, }, }, // 此處實例化一個新的router來配合當前頁面的router-view router: new VueRouter({ mode: 'abstract', base: '/', routes, }), methods: { handleClose() { this.$emit('update:visible', false); }, }, mounted() { console.log('drawer router', this.$router); this.$router.push(this.path); },};</script>

通過打印日志可以得出兩個實例化的路由:

vue 基于abstract 路由模式 實現(xiàn)頁面內(nèi)嵌的示例代碼

這樣即可實現(xiàn)在不改變當前頁面path的前提下加載其他路由中的views了。

代碼示例

以上就是vue 基于abstract 路由模式 實現(xiàn)頁面內(nèi)嵌的示例代碼的詳細內(nèi)容,更多關(guān)于vue 實現(xiàn)頁面內(nèi)嵌的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 莱西市| 临邑县| 思南县| 石台县| 新昌县| 玉田县| 涟水县| 江城| 焦作市| 高尔夫| 青冈县| 淄博市| 北辰区| 苏尼特左旗| 岗巴县| 汉阴县| 石首市| 清徐县| 尉氏县| 濉溪县| 吉木乃县| 临江市| 乐清市| 南平市| 乌恰县| 微博| 阿坝县| 临城县| 榆社县| 康平县| 沾化县| 姜堰市| 永康市| 河北区| 宜宾市| 会昌县| 同心县| 宣恩县| 财经| 信丰县| 凤冈县|