Skip to content

Commit 96cf9c7

Browse files
authored
docs: ✏️ 添加 img 组件 transformAssetUrls 配置介绍 (#1259)
* docs: ✏️ 添加 img 组件 transformAssetUrls 配置提示 * chore: once more * docs: english
1 parent 6374dd8 commit 96cf9c7

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

docs/component/img.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,36 @@
2323
const joy = 'data:image/jpeg;base64,...' // 图片文件base64
2424
```
2525

26+
:::tip 提示
27+
可以配置 `transformAssetUrls` 使 `src` 属性获得与原生 `image` 一致的体验。
28+
29+
```typescript
30+
// vite.config.(js|ts)
31+
32+
import uni from '@dcloudio/vite-plugin-uni'
33+
import { defineConfig } from 'vite'
34+
35+
export default defineConfig({
36+
plugins: [
37+
// ...
38+
uni({
39+
vueOptions: {
40+
template: {
41+
transformAssetUrls: {
42+
tags: {
43+
'wd-img': ['src']
44+
}
45+
}
46+
}
47+
}
48+
})
49+
]
50+
})
51+
```
52+
53+
修改完成后重启开发服务即可生效,查看 [uni-app issue#4997](https://github.com/dcloudio/uni-app/issues/4997#issuecomment-2456851123) 了解更多。
54+
:::
55+
2656
## 插槽
2757

2858
使用`loading` `error`插槽设置在图片加载时、加载失败后的展示内容

docs/en-US/component/img.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@ When using `file import`, note that WeChat Mini Program image tag paths accept b
2323
const joy = 'data:image/jpeg;base64,...' // Image file base64
2424
```
2525

26+
:::tip
27+
You can configure `transformAssetUrls` so that the `src` attribute works consistently with the native `image` component.
28+
29+
```typescript
30+
// vite.config.(js|ts)
31+
32+
import uni from '@dcloudio/vite-plugin-uni'
33+
import { defineConfig } from 'vite'
34+
35+
export default defineConfig({
36+
plugins: [
37+
// ...
38+
uni({
39+
vueOptions: {
40+
template: {
41+
transformAssetUrls: {
42+
tags: {
43+
'wd-img': ['src']
44+
}
45+
}
46+
}
47+
}
48+
})
49+
]
50+
})
51+
```
52+
53+
After updating the configuration, restart the development server to apply the changes.
54+
For more details, see [uni-app issue#4997](https://github.com/dcloudio/uni-app/issues/4997#issuecomment-2456851123).
55+
:::
56+
2657
## Slots
2758

2859
Use `loading` and `error` slots to set display content during image loading and after loading failure

0 commit comments

Comments
 (0)