1、新建一個font.js
2、將需要引入的字體上傳到雲上,必須是https。
3、在font.js中使用微信提供的api下載字體,wx.loadFontFace({})
// 加載字體 loadFont() { //英文 wx.loadFontFace({ family: 'xxxx', //設置一個font-family使用的名字 source: 'url("xxx.com/xxxx")', //字體資源的地址 success: console.log }) //中文 wx.loadFontFace({ family: 'xxxx', source: 'url("https://xxx.com/xxxx.otf")', success: console.log }) },
4、在要使用頁面字體的頁面下載字體
const font = require('font.js')
onLoad: function (options) { wx.hideShareMenu(); //隱藏轉發按鈕 font.loadFont(); //下載字體 }
5、在wxss中正常使用
font-family: 'xxxx';