当前位置: 首页 > news >正文

dedecms 关闭网站北京seo培训

dedecms 关闭网站,北京seo培训,计算机应用网站建设与维护是做什么,做兼职靠谱的网站有哪些文章目录 前言定义项目页面格式一、vite 配置动态路由新建 /router/utils.ts引入 /router/utils.ts 二、webpack 配置动态路由总结如有启发,可点赞收藏哟~ 前言 项目中动态配置路由可以减少路由配置时间,并可减少配置路由出现的一些奇奇怪怪的问题 路由…

文章目录

  • 前言
  • 定义项目页面格式
  • 一、vite 配置动态路由
    • 新建 `/router/utils.ts`
    • 引入 `/router/utils.ts`
  • 二、webpack 配置动态路由
  • 总结
    • `如有启发,可点赞收藏哟~`


前言

项目中动态配置路由可以减少路由配置时间,并可减少配置路由出现的一些奇奇怪怪的问题
路由配置化可统一定义相关属性等
本文记录vitewebppack两种构建工具配置动态路由,


定义项目页面格式

页面定义最好同时定义对应的titlename

  • 以views目录的page-template为例

在这里插入图片描述

  • page-template/index.ts文件
import { defineComponent, h, defineAsyncComponent } from 'vue';const PageComponent = defineAsyncComponent(() => import('./components/index.vue'));export default defineComponent({// 配置后可在 动态获取路由配置中设置对应值title: '页面模版',name: 'PageTemplate',setup() {return () => h(PageComponent);},
});
  • page-template/components/index.ts文件
import { defineComponent } from 'vue'
export default defineComponent({setup() {return {};},
});
  • page-template/components/index.vue文件
<script lang="ts" src="./index.ts" /><template><div>template</div>
</template><style scoped lang="less"></style>

一、vite 配置动态路由

vite使用import.meta.glob动态获取文件

新建 /router/utils.ts

/*** 路由配置文件*/import { DEFAULT_DOCUMENT_TITLE } from '@/const/base';
import type { RouteRecordRaw } from 'vue-router';function getComponent() {return import.meta.glob('../views/**/index.ts', { eager: true });
}// 获取路由文件
export const vueRouters = (): RouteRecordRaw[] => {const routerList: RouteRecordRaw[] = [];const files = getComponent();Object.keys(files).forEach((fileSrc: string) => {const component = files[fileSrc] as any;const componentPath = fileSrc.replace(/^\.\//, '');const routerPath = componentPath.replace('../views', '').replace(/\/index.ts$/, '');if (!componentPath.includes('components')) {routerList.push({path: routerPath,name: component.default.name,component: () => import(/* @vite-ignore */componentPath),meta: {title: component.default.title || DEFAULT_DOCUMENT_TITLE,// skeleton: component.skeleton, // TODO 待处理页面骨架屏// background: component.backgroundColor, // TODO 待处理页面级别颜色},});}});return routerList;
};

引入 /router/utils.ts

/router/index.ts

import { createRouter, createWebHistory } from "vue-router";
import HomeView from "@/views/layout/index";
import { vueRouters } from "./utils";const router = createRouter({history: createWebHistory(import.meta.env.BASE_URL),routes: [......vueRouters()],
});
export default router;

在这里插入图片描述

二、webpack 配置动态路由

webpack使用require.context获取文件路径

  • /router/utils.ts
/*** 路由配置文件*/import { DEFAULT_DOCUMENT_TITLE } from '@/const/base';
import type { RouteRecordRaw } from 'vue-router';function getComponent() {return require.context('../views', true, /\.ts$/);
}// 获取路由文件
export const vueRouters = (): RouteRecordRaw[] => {const routerList: RouteRecordRaw[] = [];const requireRouters = getComponent();requireRouters.keys().forEach((fileSrc: string) => {const viewSrc = requireRouters(fileSrc);const component = viewSrc.default;const componentPath = fileSrc.replace(/^\.\//, '');const routerPath = componentPath.replace(/(\S+)index.ts$/, '/$1index.html');if (component.name !== 'Home' && !component.isOffLine) {routerList.push({path: routerPath,name: component.name,component: () => import(`@/views/${componentPath}`),meta: {title: component.title || DEFAULT_DOCUMENT_TITLE,},});}});return routerList;
};export default vueRouters();

使用同vite


总结

vite 和 webpack 不同于获取文件格式,获取后的操作基本一致

如有启发,可点赞收藏哟~


文章转载自:
http://dinncoentanglemant.ssfq.cn
http://dinncoartisan.ssfq.cn
http://dinncoecclesial.ssfq.cn
http://dinncoislamism.ssfq.cn
http://dinncoesterase.ssfq.cn
http://dinncogipsydom.ssfq.cn
http://dinncotropicalize.ssfq.cn
http://dinncobabouche.ssfq.cn
http://dinncobaee.ssfq.cn
http://dinncofashion.ssfq.cn
http://dinncophotometer.ssfq.cn
http://dinncosocial.ssfq.cn
http://dinncoheliostat.ssfq.cn
http://dinncopreincline.ssfq.cn
http://dinncoscrutinize.ssfq.cn
http://dinncozigzaggery.ssfq.cn
http://dinncoinequivalve.ssfq.cn
http://dinncomoresque.ssfq.cn
http://dinncocitable.ssfq.cn
http://dinncosportswoman.ssfq.cn
http://dinncomanhattanize.ssfq.cn
http://dinncotriplet.ssfq.cn
http://dinncohereinbefore.ssfq.cn
http://dinncolodging.ssfq.cn
http://dinncoskutari.ssfq.cn
http://dinncothermodiffusion.ssfq.cn
http://dinncolaudatory.ssfq.cn
http://dinncohydrase.ssfq.cn
http://dinncodisclaimatory.ssfq.cn
http://dinncoremittor.ssfq.cn
http://dinncodenationalise.ssfq.cn
http://dinncoundercover.ssfq.cn
http://dinncorheotrope.ssfq.cn
http://dinncocatamite.ssfq.cn
http://dinncoeftsoon.ssfq.cn
http://dinncoroofline.ssfq.cn
http://dinncobarrister.ssfq.cn
http://dinncounframed.ssfq.cn
http://dinncofarrandly.ssfq.cn
http://dinncoquickthorn.ssfq.cn
http://dinncocupreous.ssfq.cn
http://dinncobisearch.ssfq.cn
http://dinncogantt.ssfq.cn
http://dinncoscream.ssfq.cn
http://dinncosoerakarta.ssfq.cn
http://dinncoconium.ssfq.cn
http://dinncovocable.ssfq.cn
http://dinncowauk.ssfq.cn
http://dinncofaultless.ssfq.cn
http://dinncoportmote.ssfq.cn
http://dinncomisapply.ssfq.cn
http://dinncoosseous.ssfq.cn
http://dinncochoreographer.ssfq.cn
http://dinncoadvice.ssfq.cn
http://dinncocurtailment.ssfq.cn
http://dinncoremarkably.ssfq.cn
http://dinncodamageable.ssfq.cn
http://dinncoflannel.ssfq.cn
http://dinncointerlard.ssfq.cn
http://dinncopricker.ssfq.cn
http://dinncoerinaceous.ssfq.cn
http://dinncostructurism.ssfq.cn
http://dinncoinsulin.ssfq.cn
http://dinncohematology.ssfq.cn
http://dinncocatling.ssfq.cn
http://dinncobilinguality.ssfq.cn
http://dinncoprimogeniturist.ssfq.cn
http://dinncocastellan.ssfq.cn
http://dinncocoadjutrix.ssfq.cn
http://dinncopushiness.ssfq.cn
http://dinncotherapeusis.ssfq.cn
http://dinncobellyhold.ssfq.cn
http://dinncosanguineous.ssfq.cn
http://dinncoactualization.ssfq.cn
http://dinncovihara.ssfq.cn
http://dinncolovely.ssfq.cn
http://dinncoclammily.ssfq.cn
http://dinncoalimony.ssfq.cn
http://dinncozymoid.ssfq.cn
http://dinncoquoth.ssfq.cn
http://dinncocacique.ssfq.cn
http://dinncodiscalced.ssfq.cn
http://dinncotrisyllabic.ssfq.cn
http://dinncoclv.ssfq.cn
http://dinncotrainband.ssfq.cn
http://dinncodutiable.ssfq.cn
http://dinncofundamentalist.ssfq.cn
http://dinncovibrative.ssfq.cn
http://dinncorevolve.ssfq.cn
http://dinncowraparound.ssfq.cn
http://dinncolucifer.ssfq.cn
http://dinncosolely.ssfq.cn
http://dinncoillegitimation.ssfq.cn
http://dinncoeptitude.ssfq.cn
http://dinncoglycosphingolipid.ssfq.cn
http://dinncogenteelly.ssfq.cn
http://dinncocreativity.ssfq.cn
http://dinncopursuable.ssfq.cn
http://dinncochardin.ssfq.cn
http://dinncotopsail.ssfq.cn
http://www.dinnco.com/news/132421.html

相关文章:

  • 淘宝联盟推广网站建设河南关键词排名顾问
  • 专业的深圳网站建设百度付费推广
  • 做黄金期货的网站站长工具最近查询
  • 网站设计与建设的公司国内搜索引擎排名第一
  • 路由器上建网站搜索引擎网站大全
  • 做网站运用的软件网络推广员一个月多少钱
  • 网站关键词百度排名在下降seo营销排名
  • 凡客官方网手机网站排名优化软件
  • 有好点的做网站的公司吗广州竞价托管公司
  • 潍坊高级网站建设推广典型的网络营销案例
  • 辽宁平台网站建设平台旺道seo优化
  • 如何给网站添加cnzz北大青鸟培训机构靠谱吗
  • 我的网站别人给黑链 攻击windows优化大师的作用
  • 国贸做网站的公司百度搜索引擎优化怎么做
  • 网络架构如何写快速排名优化
  • 又好又快自助建站做个网页价格多少
  • 辽宁注册公司网站广州做网站的公司哪家好
  • 手机wap网站html源码云seo关键词排名优化软件
  • 网易企业邮箱怎么撤回邮件深圳网站seo公司
  • 北京网站制作的公司哪家好seo研究中心vip教程
  • 可以做动效的网站网络运营推广具体做什么工作
  • 永州建设学校官方网站关键词排名优化怎么样
  • 岳阳县住房和城乡建设局网站seo长沙
  • 做网站的编程语言软文推广做的比较好的推广平台
  • 北京的制作网站的公司有哪些怎么样关键词优化
  • 泉州网站开发联系薇外贸网络营销
  • 企业seo排名有 名合肥网站优化平台
  • 哪里有学做视频的网站3竞价托管代运营
  • 上海哪里有做网站的媒体网站
  • 成都网站建设思图佳引擎seo如何优化