位置: 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官方代码测试自己的数据集(已训练完毕)】

  • 房产税的税收优惠政策
  • 转出未交增值税借方
  • 民办非企业可以上市吗
  • 卫生清理费计入什么科目
  • 工资可以直接进管理费用吗
  • 管道运输是什么和什么合二为一
  • 工会经费为员工计税依据是什么
  • 向境外分配股息
  • 收到虚开的普票已经入账怎么调账
  • 特许权使用费计算公式
  • 企业所得税前扣除是啥意思
  • 在建工程之前是什么
  • 其他账簿印花税是否取消
  • 供应链公司的组织架构图
  • 开专票和普票的税点
  • 其他收益小企业会计报表没有怎么填
  • 高新企业境外所得缴纳企业所得税税率为多少
  • 退货入库流程图
  • 固定资产清理需要结转吗
  • 办公室空调维修属于办公费吗
  • 发票未到的费用怎么处理
  • 如何能屏蔽自动扣费服务
  • 收到财政厅的补助怎么办
  • 20个健康生活常识
  • 电脑自带网速测试
  • 删掉广告有什么办法
  • 怎么冲财务费用
  • win7系统中怎样没有智能卡这一选项
  • 企业发生的哪些费用可以结转
  • 企业税收有哪些部分组成
  • 退回银行本票会计分录
  • 小企业会计准则适用于哪些企业
  • 取得土地使用权的方式
  • 小规模纳税人报税期是哪几个月
  • 应交税费已交税金是什么意思
  • vue3 + ts
  • php如何获取当前时间
  • uniapp dom操作
  • 什么是半监督算法
  • 个人所得的账务处理分录
  • 企业年金的功能代理人
  • 企业存货按照经济内容可以分为
  • 借款人和还款人不一致,收据打给谁
  • 车辆购置税相关法律规定
  • 资产负债表的固定资产怎么算出来的
  • 销售收入发生变动的影响
  • 社保退回的款怎么入账
  • 专利年费计入哪里
  • 合并财务报表内部往来如何抵消
  • 无形资产的处置损益
  • 物业公司维修服务范围
  • 净资产少于1元
  • 增值税发票丢失罚款多少
  • 账上的进项税额比申报多了怎么调账
  • 企业盘亏的设备会计分录
  • 个体户要怎么注册公司
  • 事业单位的在建工程包括
  • mysql跨服务器查询语句
  • xp字体无法安装
  • win8旗舰版和专业版区别
  • win8如何删除登录密码
  • win8系统找不到wifi
  • win8对机械硬盘不友好
  • 苹果手机价格
  • linux单个文件夹文件数量
  • win8怎么设置用户头像
  • android的游戏
  • perl读取文件内容
  • python添加图片
  • vue实现下载功能
  • 分享js粘帖屏幕怎么弄
  • 深入探究替换词
  • 简单谈谈你对公安工作的认识
  • jquery console.log
  • jquery mobile怎么样
  • 广东国家税务局电话
  • 增值税发票综合服务平台登录不了
  • 江苏省国税电子发票查询
  • 如何连续打印单据
  • 医保电子凭证怎么激活
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设