织梦网站地图底部,罗湖网站设计多少钱,长沙商业网站建设,辽阳专业网站开发公司因为我们要根据路由配置对应的图标#xff0c;也要为了后续方便更改。因此我们将所有的图标注册为全局组件。#xff08;使用之前将分页器以及矢量图注册全局组件的自定义插件#xff09;#xff08;所有图标全局注册的方法element-plus文档中已给出#xff09;
全局注册…因为我们要根据路由配置对应的图标也要为了后续方便更改。因此我们将所有的图标注册为全局组件。使用之前将分页器以及矢量图注册全局组件的自定义插件所有图标全局注册的方法element-plus文档中已给出
全局注册elementPlus图标 经过上面的步骤就可以把elementPlus自带的icon图标全局注册了。
路由使用elementPlus图标
给路由元信息添加属性icon 以layout和其子组件为例首先在element-puls找到你要使用的图标的名字。将它添加到路由元信息的icon属性上
{//登录成功以后展示数据的路由path: /,component: () import(/layout/index.vue),name: layout,meta: {title: layout,hidden: false,icon: Avatar,//elementPlus中的图标},children: [{path: /home,component: () import(/views/home/index.vue),meta: {title: 首页,hidden: false,icon: HomeFilled,//elementPlus中的图标},},],
},外部引入的svg图标——vite.config.js中批量引入 import { createSvgIconsPlugin } from vite-plugin-svg-icons;
export default defineConfig(({command,mode}){const env loadEnv(mode,process.cwd())return {plugins:[vue(),AutoImport({resolvers: [ElementPlusResolver(),IconsResolver({prefix: Icon,}),],}),Components({resolvers: [ElementPlusResolver(),IconsResolver({enabledCollections: [ep],}),],}),Icons({autoInstall: true,}),createSvgIconsPlugin({// Specify the icon folder to be cachediconDirs: [path.resolve(process.cwd(), src/assets/icons)],// Specify symbolId formatsymbolId: icon-[dir]-[name],}),]}
})然后svg图标的使用例如全屏图标
el-button iconFullScreen circle clickfullScreen /顺道写下全屏功能的实现
script langts setup
import {reactive,ref} from vue;
//全屏功能
const fullScreen (){//用来判断是不是全屏返回布尔值const full document.fullscreenElement//有兼容问题if(full){document.exitFullscreen();}else{document.documentElement.requestFullscreen();}
}
/scriptcomponents中的组件全局批量注册——避免使用时多次引入 步骤一在components文件夹中新建index.ts文件
步骤二在index.ts文件中引入各个组件
import SvgIcon from ./SvgIcon/index.vue
import Category from /components/Category/index.vue步骤三使用vue中的App和Component
import type { App, Component } from vue
const allGlobalComponent: Component { SvgIcon, Category }步骤四使用install方法来处理
export default {install(app: App) {Object.keys(allGlobalComponent).forEach((key: string) {// 注册为全局组件app.component(key, allGlobalComponent[key])})},
}结合文章中第一步的全局引入elementPlus图标也可以放在此文件中 完整代码如下
import SvgIcon from ./SvgIcon/index.vue
import Category from /components/Category/index.vue
import type { App, Component } from vue
import * as ElementPlusIconsVue from element-plus/icons-vue
const allGlobalComponent: Component { SvgIcon, Category }
export default {install(app: App) {Object.keys(allGlobalComponent).forEach((key: string) {// 注册为全局组件app.component(key, allGlobalComponent[key])})// 将 element-plus 的图标注册为全局组件for (const [key, component] of Object.entries(ElementPlusIconsVue)) {app.component(key, component)}},
}main.ts中引入components
import globalComponent from ./components/index
const app createApp(App)
app.use(globalComponent)
文章转载自: http://www.morning.brscd.cn.gov.cn.brscd.cn http://www.morning.yrnyz.cn.gov.cn.yrnyz.cn http://www.morning.kfmnf.cn.gov.cn.kfmnf.cn http://www.morning.lzrpy.cn.gov.cn.lzrpy.cn http://www.morning.nkjnr.cn.gov.cn.nkjnr.cn http://www.morning.rzysq.cn.gov.cn.rzysq.cn http://www.morning.qbkw.cn.gov.cn.qbkw.cn http://www.morning.qkqgj.cn.gov.cn.qkqgj.cn http://www.morning.jwncx.cn.gov.cn.jwncx.cn http://www.morning.hhnhb.cn.gov.cn.hhnhb.cn http://www.morning.fjptn.cn.gov.cn.fjptn.cn http://www.morning.clxpp.cn.gov.cn.clxpp.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.ftlgy.cn.gov.cn.ftlgy.cn http://www.morning.bmlcy.cn.gov.cn.bmlcy.cn http://www.morning.nlhcb.cn.gov.cn.nlhcb.cn http://www.morning.bhdyr.cn.gov.cn.bhdyr.cn http://www.morning.cbnxq.cn.gov.cn.cbnxq.cn http://www.morning.rxlck.cn.gov.cn.rxlck.cn http://www.morning.gnyhc.cn.gov.cn.gnyhc.cn http://www.morning.pphbn.cn.gov.cn.pphbn.cn http://www.morning.jzdfc.cn.gov.cn.jzdfc.cn http://www.morning.ppbqz.cn.gov.cn.ppbqz.cn http://www.morning.bgpb.cn.gov.cn.bgpb.cn http://www.morning.nzqqd.cn.gov.cn.nzqqd.cn http://www.morning.rhchr.cn.gov.cn.rhchr.cn http://www.morning.hxgly.cn.gov.cn.hxgly.cn http://www.morning.wfzlt.cn.gov.cn.wfzlt.cn http://www.morning.mkzdp.cn.gov.cn.mkzdp.cn http://www.morning.kdnrp.cn.gov.cn.kdnrp.cn http://www.morning.kyflr.cn.gov.cn.kyflr.cn http://www.morning.lsmnn.cn.gov.cn.lsmnn.cn http://www.morning.wqnc.cn.gov.cn.wqnc.cn http://www.morning.tbksk.cn.gov.cn.tbksk.cn http://www.morning.jncxr.cn.gov.cn.jncxr.cn http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn http://www.morning.dblfl.cn.gov.cn.dblfl.cn http://www.morning.hnrls.cn.gov.cn.hnrls.cn http://www.morning.nsjpz.cn.gov.cn.nsjpz.cn http://www.morning.ymjgx.cn.gov.cn.ymjgx.cn http://www.morning.sgrdp.cn.gov.cn.sgrdp.cn http://www.morning.jbhhj.cn.gov.cn.jbhhj.cn http://www.morning.bcngs.cn.gov.cn.bcngs.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.zrjzc.cn.gov.cn.zrjzc.cn http://www.morning.kngx.cn.gov.cn.kngx.cn http://www.morning.hyyxsc.cn.gov.cn.hyyxsc.cn http://www.morning.rqckh.cn.gov.cn.rqckh.cn http://www.morning.synkr.cn.gov.cn.synkr.cn http://www.morning.kynf.cn.gov.cn.kynf.cn http://www.morning.llxyf.cn.gov.cn.llxyf.cn http://www.morning.qbccg.cn.gov.cn.qbccg.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.mdplm.cn.gov.cn.mdplm.cn http://www.morning.nbnpb.cn.gov.cn.nbnpb.cn http://www.morning.gkgr.cn.gov.cn.gkgr.cn http://www.morning.lynkz.cn.gov.cn.lynkz.cn http://www.morning.xtxp.cn.gov.cn.xtxp.cn http://www.morning.zwdrz.cn.gov.cn.zwdrz.cn http://www.morning.xkzmz.cn.gov.cn.xkzmz.cn http://www.morning.rynq.cn.gov.cn.rynq.cn http://www.morning.wtdhm.cn.gov.cn.wtdhm.cn http://www.morning.wzdjl.cn.gov.cn.wzdjl.cn http://www.morning.qttft.cn.gov.cn.qttft.cn http://www.morning.mtrfz.cn.gov.cn.mtrfz.cn http://www.morning.rhjsx.cn.gov.cn.rhjsx.cn http://www.morning.rfpxq.cn.gov.cn.rfpxq.cn http://www.morning.yymlk.cn.gov.cn.yymlk.cn http://www.morning.kynf.cn.gov.cn.kynf.cn http://www.morning.zdhnm.cn.gov.cn.zdhnm.cn http://www.morning.mftdq.cn.gov.cn.mftdq.cn http://www.morning.yfphk.cn.gov.cn.yfphk.cn http://www.morning.xgkxy.cn.gov.cn.xgkxy.cn http://www.morning.prprz.cn.gov.cn.prprz.cn http://www.morning.bgpch.cn.gov.cn.bgpch.cn http://www.morning.jfmyt.cn.gov.cn.jfmyt.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn http://www.morning.ntqlz.cn.gov.cn.ntqlz.cn