uni-app中的字体图标引入 - 前端笔记-方式一:考虑兼容的 1.在app.vue引入字体图标(在app.vue引入的图标为全局图标) style &...

学习笔记

点滴记忆
回忆过往
首页>> web前端 >>uni-app中的字体图标引入 - 前端笔记
方式一:考虑兼容的

1.在app.vue引入字体图标(在app.vue引入的图标为全局图标)
    
<style>
    /*每个页面公共css */
    @import url("./static/font/style.css");
</style>


2.改变字体图标的style.css引入方式   使用 ~@/绝对路径的方式

    为修改前的style.css引入方式
@font-face {
  font-family: 'icomoon';
  src: url('fonts/icomoon.eot?pr8w9y');
  src: url('fonts/icomoon.eot?pr8w9y#iefix'format('embedded-opentype'),
    url('fonts/icomoon.ttf?pr8w9y'format('truetype'),
    url('fonts/icomoon.woff?pr8w9y'format('woff'),
    url('fonts/icomoon.svg?pr8w9y#icomoon'format('svg');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}
      修改后的style.css的引入方式
@font-face {
  font-family: 'icomoon';
  src:  url('~@/static/font/fonts/icomoon.eot?pr8w9y');
  src:  url('~@/static/font/fonts/icomoon.eot?pr8w9y#iefix'format('embedded-opentype'),
    url('~@/static/font/fonts/icomoon.ttf?pr8w9y'format('truetype'),
    url('~@/static/font/fonts/icomoon.woff?pr8w9y'format('woff'),
    url('~@/static/font/fonts/icomoon.svg?pr8w9y#icomoon'format('svg');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

3.在页面中 使用 字体图标  我这里使用的icomoon字体图标库, (其他字体图标引入方式一样)
        <view class="icon-books"></view>


    
方式二:不考虑兼容的   使用类名引入  
    直接 用css 文件   iconfont.css   文件放到  项目里面
    app.vue引入iconfont.css 
    /*引入字体图标*/
    @import './common/iconfont.css';
    修改 iconfont.css文件 内容 
    删掉了很多兼容性文件   按下图引入即可     使用类名在页面使用 字体图标     这个是 不考虑 兼容的写法
@font-face {font-family: "iconfont";
  src:url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAfIAAsAAAAAEDwAAAd6AAEAAAAAAAAAAAAAAAAAAA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DYLKhF90BEzCix+FgZkLMCQmBWYMsOW4zNaOIdDLAGmuSlAoZGXUCl5Ax2NfAAW/wUGtPMXhjSKgym7xeSMGePby9GrN8ZBcIZxD3aipESZXOntv1Gvw8B2mlbyj5ytDZqydvu+MCEXsU/e6FZEgWKK8ClcD0MgWJgcTlIakWVVVSpo33KieHD1xjiIUnMGxn1rO1FSy8uV5/u/Ua/DwBHD/rT+R8529UBDSZ0AfLFTomGb0jVvdIsQpQKpL1MEPokSA3cTsARv5nCSEpPBuayoyHQqKbusnhvn/wogZZ/WIipOTAIJJZJYEkklk1wKKaVBGqVJmqVFWpk+Ybcfu4B0Nw92VEuysTt7J309zDNjzsFmOZ0CTf5EE80ndhlkZ7DJX0xGSMQk+TK7pRDMi4FsTGpeMS3mHvOAecQ8YZ4xL6rXgwMA'format('woff2')
}

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

.icon-icon_yulan:before {
  content: "\eb8a";
}

.icon-daibanshixiang:before {
  content: "\ec4e";
}


第三,直接使用 Unicode

        字体图片里面 和Unicode相关是  文件是  .ttf    把ttf文件引入    直接使用Unicode 文件使用
 

×

感谢您的支持,我们会一直保持!

扫码支持
请土豪扫码随意打赏

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

打赏作者
版权所有,转载注意明处:前端笔记 » uni-app中的字体图标引入

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)