family:fontFamily,
source:`url(${testurl})`,//其他文件夹的平台绝对路径
success:(res) => {
this.selectedLayer.style.fontFamily = fontFamily;
this.displayedFonts[i].loaded = true;
console.log(res)
this.displayedFonts[i].download = true;
this.setLayerText(this.selectedLayer, this.selectedLayer.srcText);
},
fail: function(res) {
//this.fonts[i].download = false;
console.log(res)
},
})``` - 发布:2024-09-05 09:46
- 更新:2025-09-10 11:38
- 阅读:836
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 4.26
手机系统: Android
手机系统版本号: Android 14
手机厂商: 一加
手机机型: ace2
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
family:fontFamily,
source:`url(${testurl})`,//其他文件夹的平台绝对路径
success:(res) => {
this.selectedLayer.style.fontFamily = fontFamily;
this.displayedFonts[i].loaded = true;
console.log(res)
this.displayedFonts[i].download = true;
this.setLayerText(this.selectedLayer, this.selectedLayer.srcText);
},
fail: function(res) {
//this.fonts[i].download = false;
console.log(res)
},
})```
family:fontFamily,
source:`url(${testurl})`,//其他文件夹的平台绝对路径
success:(res) => {
this.selectedLayer.style.fontFamily = fontFamily;
this.displayedFonts[i].loaded = true;
console.log(res)
this.displayedFonts[i].download = true;
this.setLayerText(this.selectedLayer, this.selectedLayer.srcText);
},
fail: function(res) {
//this.fonts[i].download = false;
console.log(res)
},
})``` 预期结果:
字体成功加载
字体成功加载
实际结果:
加载失败报错loadFontFace:fail [object Object]。
加载失败报错loadFontFace:fail [object Object]。
bug描述:
uni.loadFontFace只能加载_www/static/目录下的字体,其他目录都会报错.报错信息:loadFontFace:fail [object Object]。
请问你的字体文件放在哪个文件夹能访问,我放在/static/fonts下,android怎么折腾也访问不了
-
-
回复 2***@qq.com: 使用plus.io.convertLocalFileSystemURL('_www/static/app/fonts/AlibabaPuHuiTi-3-65-Medium.ttf')去加载字体,在ios上,开发阶段、正式包都正常,但是在android开发阶段正常,正式包报路径错误:loadFontFace:fail NetworkError: A network error occurred.
最终解决方案:
- APP:每个页面的onLoad中使用uni.loadFontFace加载/static/app/fonts下的字体
- source:
url("/static/app/fonts/AlibabaPuHuiTi-3-65-Medium.ttf")
- source:
- 小程序:在App.vue的onLaunch中使用uni.loadFontFace加载网络字体+global:true
2025-11-21 23:08
- APP:每个页面的onLoad中使用uni.loadFontFace加载/static/app/fonts下的字体
删库在逃程序员
我是加载网络路径的,也会出现
靠字用的好啊,已经不知道靠了多少次
2024-10-30 10:55