赞
踩
使用uni.loadFontFace加载网络字体,小程序开发工具正常,但安卓手机实机无法正常加载。且success和error的回调没有。经摸索,是网络字体的跨域问题。
在宝塔的配置文件里,注意在443下添加,因为小程序要https。
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
//需要注意的是每个页面都要调用,我是写在mixin里面
uni.loadFontFace({
family: 'Softbrush',
source: 'url("https://www.xxx.com/fonts/Softbrush.ttf")',
success() {
console.log('字体加载完毕')
},
error(){
console.log('字体加载失败');
},
complete(){
console.log('字体加载');
}
})
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。