步骤

基本使用

1 下载存放

从阿里图标库中下载压缩包,解压开目录如下
在这里插入图片描述
在vue项目的assets下创建font文件夹,把这些文件复制到font文件夹下,为了有条理再创建styles文件夹,目录如下
在这里插入图片描述

2 设置

在styles文件夹下创建font.css,复制下载下来的iconfont.css内容到font.css中,原先内容如下,将该文件内容复制到font.css再根据自己的项目修改url地址

@font-face {font-family: "iconfont";
  src: url('iconfont.eot?t=1562837780571'); /* IE9 */
  src: url('iconfont.eot?t=1562837780571#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAnIAAsAAAAAExwAAAl7AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCEQgqWNJFpATYCJANECyQABCAFhG0HgXYb4w9RlHBWF9nPAbcdHsFx60KdIteX+UGdp2TGZF5HuziCaknruZ1PMdlMeRRCosjCpKCQEo1DgjBLEp77a+7tpcjjd3w3H2SRFSrM37xAA5uFAoEGOtAn1AlDQt4JBaw7/7hpP0jTJuAB1rGKOq0z0UCYVmymZHOYscKEd0Nqjs0cps4OOxNZdghAA/f3a+h+r/5aNQ4jzz7YAnTEL+reLbN94+QBRf6ItE2oREYJPiGagrVJWiZesROzH8w4gV6LGhn3+kbGoURifGDCI9+1oCRSKgtiQndBZ4bSnDCuFepuPjefgC/2/eOfbJTQ6CiYSfcf9trQUX/UX2W73TZV9hx2V43XqyjYB/I1/0Vm0SNA8R2Xr7e2wHUxn5hRf9tSUZOTJTC8UaSOn3/zunTr0atPvwGDhgyD6MRQPwK+Fw/bPkriP3UqAdBQGVCoAkiqAjqoBuikOqCLGoBuagJ6qAXopTagjzqAfuoCBqgHGKS+akMOnkKpYSoeuXsVOALlOUC+vAW8q07Ba4vmemCoDd3XpCb0ZHLnoYJdgsVEhUZyqJiQo4eGYjyeOJsOZQwGxIhBBDGRAlScTo+LfSSfv8P3qcz7Ce7/TB74XNFj0znEUK9da53SHDyFwurV+pNNF6wqwXWfLlBhVt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BMBX5I6TPrOdSIi8pN6PYh6Lftshl/WLdHSaJPcCvEZjx1RocvcxFF0F0JLEuZ+3yRK5fOYZMz030A/xii7kKEW3azWDnEkj0jf7REMQ04SyeeRadNDf9KUSjnvMk3GIyhzR0IWrdPaiJwVaR/DxZyjtbLE249CrgUhiyxY8Vt6EpIU/+JEhildQdiP4korTmW6ssiVpUm1g8j5Ehch+kg1CnkvRyTZN81DjGbyGnQnmqTITk5VZA6fH5175PStynQaibwokdERndEV3dETvfH8anMMxGAMxbBRa9RB0YGKLD8spC7ndgHNWXaZ+gbKZ5QnWERZyBXWUYVy0WdIcTmhoe96uqYEFdtW8fnCQmrzpbiKLqjyfMMglVJXIVMyqRrIpwtJSZ3uUurH7LKNUVhKbfRKAAA=') format('woff2'),
  url('iconfont.woff?t=1562837780571') format('woff'),
  url('iconfont.ttf?t=1562837780571') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
  url('iconfont.svg?t=1562837780571#iconfont') format('svg'); /* iOS 4.1- */
}

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

.dp-icon-smail:before {
  content: "\e6d8";
}

.dp-icon-good:before {
  content: "\e6d9";
}

.dp-icon-bad:before {
  content: "\e6da";
}

.dp-icon-basic-ope:before {
  content: "\e6db";
}

.dp-icon-close:before {
  content: "\e6dc";
}

.dp-icon-service-exp-light:before {
  content: "\e6dd";
}

.dp-icon-basic-ope-light:before {
  content: "\e6de";
}

.dp-icon-service-exp:before {
  content: "\e6df";
}

.dp-icon-down:before {
  content: "\e6e0";
}

.dp-icon-use-exp-light:before {
  content: "\e6e1";
}

.dp-icon-smart-service-light:before {
  content: "\e6e2";
}

.dp-icon-smart-service:before {
  content: "\e6e3";
}

.dp-icon-up:before {
  content: "\e6e4";
}

.dp-icon-use-exp:before {
  content: "\e6e5";
}

.dp-icon-increase:before {
  content: "\e6e6";
}

.dp-icon-decrease:before {
  content: "\e6e7";
}

要把url地址改一下,改成相对地址,比如在我的项目目录中,地址可改变如下

@font-face {
    font-family: 'iconfont';
    src: url('../font/iconfont.eot');
    src: url('../font/iconfont.eot?#iefix') format('embedded-opentype'),
    url('../font/iconfont.woff2') format('woff2'),
    url('../font/iconfont.woff') format('woff'),
    url('../font/iconfont.ttf') format('truetype'),
    url('../font/iconfont.svg#iconfont') format('svg');
}
3 引入

在main.js中引入css文件

import './assets/styles/font.css'
4 使用

每个图标都有自己的unicode码,使用的时候直接替换以下span的unicode码(打开demo_index.html可看到码)

<span class="iconfont">&#x33;</span>

在这里插入图片描述
或者因为font.css里设置了class,用class也可以,更好理解

<span class="iconfont dp-icon-good"></span>

修改样式

在具体组件中使用的时候有时候想改icon的颜色,大小
直接在template中对其进行设置,比如test-part下的图标

.test-part iconfont{
color:red;
font-size:32px;
}

【注意】template不可以加scope,否则设置不了。font-size用来改变大小,对iconfont的使用可以看做和字体类似

Logo

前往低代码交流专区

更多推荐