将 SVG 图标 包装为 Vue 组件来使用

设计师为我们单独提供了设计稿中的图标,为了方便使用,我们在这里把它制作为字体图标。制作字体图标的工具有很多,在这里我们推荐大家使用:https://www.iconfont.cn/

一、注册账户

二、创建项目 

 

三、上传图标到项目

可以在首页中挑选符合项目的图标加入购物车,或者是ui已经设计好的svg,导入项目:

 

四、生成链接

 

五、配置到项目中使用

在styles文件下创建icon.less,把复制过来的代码粘贴过来

@font-face {
  font-family: "toutiao"; /* Project id 3852472 */
  src: url('//at.alicdn.com/t/c/font_3852472_bvqgbaxp2el.svg?t=1672913556576#toutiao') format('svg');
}

.toutiao {
  font-family: "toutiao" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.toutiao-Icon_arrow-down:before {
  content: "\e602";
}

.toutiao-a-Icon_arrow-right:before {
  content: "\e603";
}

.toutiao-Icon_eyes:before {
  content: "\e604";
}

.toutiao-Icon_profile:before {
  content: "\e605";
}

.toutiao-a-Icon_fullscreen:before {
  content: "\e606";
}

 在index.less(全局样式)中导入,注意全局样式必须引入main.js才会生效

@import "./icon.less";//less文件导入后面加相对路径!!
//main.js
// 导入全局样式
import '@/styles/index.less'

使用:在标签上加上class=toutiao toutiao-xxx",即可使用对应的图标,eg:

  <i slot="icon" class="toutiao toutiao-Icon_arrow-down"></i>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值