# new URL(url, import.meta.url).href
new URL(url, import.meta.url).href
说明:第一个 url 为图片的相对路径
# Vue 的绑定功能来动态设置 img 的 src 属性
即用 ref (),如下
| <template> | |
| <div> | |
| <img :src="imageUrl" alt="Dynamic Image" /> | |
| </div> | |
| </template> | |
| <script> | |
| import { ref } from 'vue'; | |
| export default { | |
| setup() { | |
| const imageUrl = ref('path_to_your_image.jpg'); | |
|     // 你可以在需要的时候更改 imageUrl 的值,比如在方法或计算属性中 | |
|     // 例如: | |
|     // function updateImage() { | |
|     //   imageUrl.value = 'new_path_to_image.jpg'; | |
|     // } | |
| return { imageUrl }; | |
|   } | |
| }; | |
| </script> | 
