svg替代iconfont的好處(不管是基於Vue、Jquery),都推薦svgcss
http://www.woshipm.com/pd/463866.htmlhtml
svg圖標庫,svg圖標在線製做vue
https://icomoon.io/app/#/selectgit
svg體積優化github
https://jakearchibald.github.io/svgomg/?utm_source=next.36kr.comvim
示例代碼(建議uniapp運行環境,修改也能夠vue環境運行,需支持sass處理)sass
1 <template>
2 <view>
3 <view class="svg-list">
4 <view class="icon-facebook"></view>
5 <view class="icon-twitter"></view>
6 <view class="icon-feed"></view>
7 <view class="icon-youtube"></view>
8 </view>
9 </view>
10 </template>
11
12 <script>
13 export default { 14 data() { 15 return { 16
17 }; 18 } 19 } 20 </script>
21
22 <style lang="scss">
23 $icons: google-plus, 24 facebook, 25 twitter, 26 feed, 27 youtube, 28 vimeo, 29 lanyrd, 30 forrst, 31 deviantart, 32 steam, 33 github, 34 wordpress, 35 blogger, 36 tumblr, 37 soundcloud, 38 linkedin, 39 lastfm, 40 delicious, 41 stumbleupon, 42 pinterest, 43 xing, 44 flattr; 45
46
47 .svg-list { 48 display: flex; 49 [class*="icon-"] { 50 margin: 2%; 51 } 52 } 53
54 [class^="icon-"] { 55 display: block; 56 width: 64upx; 57 height: 64upx; 58 text-indent: 100%; 59 overflow: hidden; 60 white-space: nowrap; 61 background: url(http://www.w3cplus.com/sites/default/files/blogs/2015/1506/sprite.svg) no-repeat;
62
63 @for $i from 1 through length($icons) { 64 &.icon-#{nth($icons,$i)} { 65 background-position: 0 -1 * (($i - 1) * 84upx); 66 } 67 } 68 } 69 </style>
來自大漠的一篇博文:https://www.w3cplus.com/svg/create-svg-sprite-sheet.htmlapp