vue中使用Symbol的方式引用iconfont
阿新 • • 發佈:2022-04-12
前提工作,先把自己要使用的圖示都加入iconfot資原始檔中。
1. 選擇Symbol的方式,生成連結
2. 在index.html中引入js
<script src="https://at.alicdn.com/t/font_3298751_bg4cvlhc5ga.js"></script>
3. 使用iconfont的地方寫:此處的href 名字是在平臺定義的iconfont名稱
<svg class="icon" aria-hidden="true"> <use :xlink:href="'#icon-'+item.Icon" /> </svg>
4. 修改css及樣式
. 在index.html 先全域性設定icon 樣式
.icon { width: 1em; height: 1em; vertical-align: -0.15em; fill: currentColor; overflow: hidden; }
. 在使用的vue檔案中再個性化設定顏色大小等
.icon { height: 14px; width: 14px; margin-right: 12px; }
// 修改圖示顏色 .icon:last-of-type { fill: #5f5f69; } .el-submenu:hover, .el-submenu.is-active, .el-menu-item.is-active, .el-menu-item:hover { span { color: #3585ff; } .icon:last-of-type { fill: #3585ff; } }