Skip to main content
版本:v3

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