位置: IT常识 - 正文

vue3使用svg图标多种方式(vue引用svg矢量图)

编辑:rootadmin
vue3使用svg图标多种方式

推荐整理分享vue3使用svg图标多种方式(vue引用svg矢量图),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:vue svga,vue中使用svg图标,vue3 svg,vue-svg-loader,vue中使用svg图标,vue svgicon,vue3 svg,vue3 svg,内容如对您有帮助,希望把文章链接给更多的朋友!

方式1使用在线链接访问 在iconfont找到自己的项目的图标选择Symbol获取在线链接 2:在vue3项目中找到public的index.html进行script进行引入

打开浏览器看:这样就会自动注入到body下

在项目直接使用

//控制图标的大小 <svg style="width: 10px; height: 10px"> <use href="#icon-shanchu"></use> </svg>

显示出了删除的图标

封装的写法(上面的代码写着太重复下面进行封装) 1:新建一个专门获取svg图标的组件 icon.vue (svg/index.vue)

<template> <div> <svg :style="style"> <use :href="names"></use> </svg> </div></template><script setup>import { defineProps, withDefaults } from "vue";const props = defineProps({ name: { type: String, default: "", }, style: { type: Object, default: () => { return { width: 10, height: 10, color: "", }; }, },});const names = `#${props.name}`;</script><style lang="scss" scoped></style>vue3使用svg图标多种方式(vue引用svg矢量图)

需要显示图标的界面

<template> <div class="home"> <icon :style="{ width: 10, height: 10, color: 'red' }" name="icon-shanchu" ></icon> <icon :style="{ width: 10, height: 10, color: 'red' }" name="icon-shanchu" ></icon> </div></template><script setup>import { ref } from "vue";import icon from "../assets/svg/index.vue";</script><style lang="scss"></style>

假如你既引用了iconfont的图标也自定义了图标:直接放在一起根据传输的name指定使用哪一个图标 icon.vue (svg/index.vue)

<template> <div> <svg :style="style"> <use :href="names"></use> </svg> // 自定义的图标 <svg width="0" height="0"> <defs> <symbol id="more" viewBox="0 0 100 100"> <circle r="5" cx="20" cy="25" fill="transparent" stroke="green" ></circle> <circle r="5" cx="20" cy="50" fill="currentColor"></circle> <circle r="5" cx="20" cy="75" fill="currentColor"></circle> <line x1="40" y1="25" x2="90" y2="25" stroke-width="8" stroke="currentColor" ></line> <line x1="40" y1="50" x2="90" y2="50" stroke-width="8" stroke="currentColor" ></line> <line x1="40" y1="75" x2="90" y2="75" stroke-width="8" stroke="currentColor" ></line> </symbol> </defs> </svg> </div></template><script setup>import { defineProps, withDefaults } from "vue";const props = defineProps({ name: { type: String, default: "", }, style: { type: Object, default: () => { return { width: 10, height: 10, color: "", }; }, },});const names = `#${props.name}`;</script><style lang="scss" scoped></style>

使用:

<template> <div class="home"> <icon :style="{ width: 10, height: 10, color: 'red' }" name="icon-shanchu" ></icon> <icon :style="{ width: 10, height: 10, color: 'red' }" name="icon-shanchu1" ></icon> <icon :style="{ width: 20, height: 20, color: 'red' }" name="more"></icon> </div></template><script setup>import { ref } from "vue";import icon from "../assets/svg/index.vue";</script><style lang="scss"></style>

假如你是复制的iconfont官网的图标svg的代码:

你直接cv到项目也可以直接使用:

<svg t="1673881805558" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1076" width="200" height="200" > <path d="M658.276045 767.993958 658.276045 274.295l329.126 0L987.402045 219.44 658.276 219.44l0-18.281c0-80.787046-65.492992-146.284032-146.276045-146.284032-80.790016 0-146.276045 65.496986-146.276045 146.284032l0 18.281L36.597 219.44l0 54.855 109.695 0 0 694.83L877.7 969.125l0-548.55-54.855 0L822.845 914.27l-621.69 0L201.155 274.295l164.569 0 0 493.699 54.848 0L420.572 274.295l182.85 0 0 493.699L658.276 767.994zM420.571034 219.440026l0-18.281c0-50.492006 40.932966-91.420979 91.428966-91.420979 50.489037 0 91.420979 40.928973 91.420979 91.420979l0 18.281L420.571 219.440026z" p-id="1077" ></path> </svg>

效果如下:

我们还可以把上面的代码进行改造直接使用在 icon.vue (svg/index.vue)改造

<template> <div class="home"> <icon :style="{ width: 10, height: 10, color: 'red' }" name="icon-shanchu" ></icon> <icon :style="{ width: 10, height: 10, color: 'red' }" name="icon-shanchu1" ></icon> <icon :style="{ width: 20, height: 20, color: 'red' }" name="more"></icon> <svg t="1673881805558" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1076" width="200" height="200" > <path d="M658.276045 767.993958 658.276045 274.295l329.126 0L987.402045 219.44 658.276 219.44l0-18.281c0-80.787046-65.492992-146.284032-146.276045-146.284032-80.790016 0-146.276045 65.496986-146.276045 146.284032l0 18.281L36.597 219.44l0 54.855 109.695 0 0 694.83L877.7 969.125l0-548.55-54.855 0L822.845 914.27l-621.69 0L201.155 274.295l164.569 0 0 493.699 54.848 0L420.572 274.295l182.85 0 0 493.699L658.276 767.994zM420.571034 219.440026l0-18.281c0-50.492006 40.932966-91.420979 91.428966-91.420979 50.489037 0 91.420979 40.928973 91.420979 91.420979l0 18.281L420.571 219.440026z" p-id="1077" ></path> </svg> //改造好了直接使用 <icon :style="{ width: 20, height: 20, color: 'red' }" name="icon"></icon> </div></template><script setup>import { ref } from "vue";import icon from "../assets/svg/index.vue";</script><style lang="scss"></style>

本文链接地址:https://www.jiuchutong.com/zhishi/293156.html 转载请保留说明!

上一篇:Vue实现生成二维码(vue生成二维码分享)

下一篇:【swinUnet官方代码测试自己的数据集(已训练完毕)】

  • 个人出租房屋的个人所得税税率
  • 自然人个税申报错误怎么更改?
  • 用票据付款怎么做账
  • 新公司季初资产总额和季末资产总额怎么填
  • 出差补贴需要交税
  • 个体户经营税收政策
  • 房地产开发企业预缴增值税
  • 复合肥生产企业排名
  • 多交的所得税如何做分录
  • 营改增后怎么计算税费
  • 公益性支出所得税扣除比例
  • 已认证未抵扣什么意思
  • 用于出口的进项可以抵扣吗
  • 进货发票未到怎么做账
  • 公司进项销项税差异较大
  • 私人企业的资金来源
  • 小规模纳税人亏损交所得税吗
  • 房屋修缮费交增值税吗
  • win10玩游戏时弹出error
  • 暂估入库入库单范本
  • 公司购入二手设备 如何开具发票
  • PHP:mb_ereg_replace()的用法_mbstring函数
  • 查补以前年度增值税怎么申报
  • win11快捷键大全
  • 社保申报已扣款还能作废吗
  • php接收ajax请求
  • nginx连接超时时间设置多少
  • 框架 frame
  • 命令提示符用不了怎么办
  • 对公账户怎么打印
  • 购买商品发生的费用计入
  • 现金流量表中的现金流量包括哪些
  • 代扣代缴完税凭证抵扣期限
  • 公司人员工资计算方法
  • 管理费用主要核算内容包括什么?
  • 固定资产管理台账
  • 本期数值与去年同期数值之差称为什么
  • 税率变更协议怎么写
  • 租赁公司开票没有写数量可以开吗?
  • 转让无形资产或其他资产
  • 计提坏账准备资产总额会减少吗
  • 印花税签合同
  • 留抵会计分录
  • 交租金没有发票怎么办
  • 进项发票认证多了留抵多久
  • 所有者权益科目有哪些
  • 企业发生装修费就计入长期待摊费用吗还是
  • 小微企业a201010表怎么填
  • 财务软件服务费合同印花税
  • 购买本公司产品未付款需要签名字吗
  • mysql默认8小时自动断开
  • mysql用处
  • win8任务管理器在哪
  • win10的时间设置
  • linux系统中的用户分为哪几类
  • xp桌面字体有阴影怎么去掉
  • centos7 tcp6
  • 电脑重装xp系统怎么设置
  • windows7旗舰版怎么扩展c盘
  • win7如何删除系统启动项
  • win10系统中断怎么解除
  • 网页制作颜色搭配
  • opengl怎么导入模型
  • linux中的shell命令
  • jquery.min.js源代码
  • android使用webview加载网页
  • 编程中的python
  • vue router 组件
  • 表单失去焦点事件
  • python神奇的小海龟
  • js获取当前点击事件的节点
  • jquery的设计模式
  • jquery调用controller
  • 前方高能(莞尔wr)晋江
  • bootstrap需要学多久
  • 网上申领的电子发票如何读入金税盘
  • 施工企业建筑机械管理机构主要职责是负责建筑机械的
  • 公对私转账怎么开票
  • 养老专业在职研究生好吗
  • 广东广州税务局电话
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设