vue中使用阿里巴巴矢量图标库的图标


前言

vue一般使用element-ui等框架来构建页面样式,但是有时候里面自带的图标并不能满足我们的需求,而阿里巴巴矢量图标库里面正好有大量图标,现在就来学习一下如何引入图标。


一、配置

vue 2.x版本

二、使用步骤

1.下载图标

去阿里巴巴矢量图标库官网下载图标(建议:下载的时候先点小购物车添加到库,然后再点击右上角的小购物车将所有的图标添加到一个库后一起下载
在这里插入图片描述
在这里插入图片描述

2.使用

1.解压

下载了之后,解压压缩包,会看到如下文件,其中的demo_index.html文件时教程文件,可以打开在浏览器里面查看
在这里插入图片描述
之后将除了demo文件以外的所有文件导入到vue项目中(位置随意,能找到就行)
在这里插入图片描述

2.引入并使用

因为我想要彩色图标,所以按照教程使用svg的方式引入,首先,在index.html中引入iconfont.js
index.html

<!DOCTYPE html>
<html lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="icon" href="<%= BASE_URL %>favicon.ico">
  <title>
    <%= htmlWebpackPlugin.options.title %>
  </title>
  <!-- 加了这句 -->
  <script src="./icon/iconfont.js"></script>
  <!-- 加了这句 -->
</head>

<body>
  <noscript>
    <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
        Please enable it to continue.</strong>
  </noscript>
  <div id="app"></div>
  <!-- built files will be auto injected -->
</body>
</html>

之后在对应的vue文件中添加style,并写上对应的html代码即可

<template>
  <div>
    <svg class="icon" aria-hidden="true">
      <use xlink:href="#icon-a-caozhiwu"></use>
    </svg>
    <svg class="icon" aria-hidden="true">
      <use xlink:href="#icon-a-lvsedeshumuzhiwu"></use>
    </svg>
    <svg class="icon" aria-hidden="true">
      <use xlink:href="#icon-a-huahuaduozhiwu"></use>
    </svg>
    <svg class="icon" aria-hidden="true">
      <use xlink:href="#icon-a-guoshushuzhiwu"></use>
    </svg>
    <svg class="icon" aria-hidden="true">
      <use xlink:href="#icon-a-meiguihuahuahuaduozhiwu"></use>
    </svg>
    <svg class="icon" aria-hidden="true">
      <use xlink:href="#icon-a-shuiguoguoshi"></use>
    </svg>
  </div>
</template>

<script>
export default {};
</script>

<style>
.icon {
  width: 10em; /* 调节图标宽度 */
  height: 10em; /* 调节图标高度 */
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>

3.结果

在这里插入图片描述
大功告成!有什么问题欢迎在评论区留言。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值