assets
API_LEVEL
2.0
开始支持,API 兼容性请参考 API_LEVEL。
用于处理资源文件路径, 拼接 basePath
。并可传入参数对图片进行 rtl 路径转换,用于小程序的 RTL 适配。
类型
function assets(basePath: BasePath): AssetsPathFunc
参数
BasePath
类型 | 说明 |
---|---|
string | 基础路径,会拼接在资源文件路径之前 |
AssetsPathFunc
类型 | 说明 |
---|---|
(path: Path, isRtl?: IsRtl) => ResultPath | 资源文件路径构造函数 |
Path
类型 | 说明 |
---|---|
string | 资源文件路径 |
IsRtl
类型 | 说明 |
---|---|
boolean | 是否需要拼接 rtl 路径 |
ResultPath
类型 | 说明 |
---|---|
string | 最终文件路径 |
代码示例
import { assets } from '@zos/utils'
const imagePath = 'zeppos-logo.png'
const assetsPathFunc = assets('img')
console.log(assetsPathFunc(imagePath)) // img/zeppos-logo.png
console.log(assetsPathFunc(imagePath, true)) // img/zeppos-logo@rtl.png