共计 606 个字符,预计需要花费 2 分钟才能阅读完成。
vite:在 vue3 中动态引入静态资源图片需要使用 new URL(url, import.meta.url) 方法
注意:如果作为背景图片,要使用相对路径,不然打包时无法解析
参考:静态资源处理 | Vite 官方中文文档
const imgUrl = [new URL('../src/assets/images/home/home_card_1.png', import.meta.url).href,
new URL('../src/assets/images/home/home_card_2.png', import.meta.url).href,
new URL('../src/assets/images/home/home_card_3.png', import.meta.url).href,
new URL('../src/assets/images/home/home_card_4.png', import.meta.url).href,
new URL('../src/assets/images/home/home_card_5.png', import.meta.url).href,
new URL('../src/assets/images/home/home_card_6.png', import.meta.url).href,
]
将图片作为背景图片使用
webpack:通过 require 动态引入
![vue3 中动态引入静态资源 vue3 中动态引入静态资源](https://yojack.cn/wp-content/themes/wordpress-theme-puock-master/assets/img/z/load.svg)
原文地址: vue3 中动态引入静态资源
正文完