Jak*_*ang 3 vue.js vuejs3 vite
我已将 Vite 配置为"@"
别名"./src"
。
直接使用别名就<img>.src
可以了:
<!-- this is ok -->
<img src="@/assets/icon-1.svg">
Run Code Online (Sandbox Code Playgroud)
但将src
作为 prop 传递是行不通的:
<!-- ComponentA -->
<template>
<img :src="imgSrc">
</template>
<!-- Parent Component: alias not resolved as expected; imgSrcWithAlias is "@/assets/icon-1.svg" -->
<component-a :img-src="imgSrcWithAlias" />
Run Code Online (Sandbox Code Playgroud)
传递 props 时是否有使用文件路径别名的解决方案?
资产 URL 必须在脚本中使用关键字手动解析import
:
<script setup>
import imgSrcWithAlias from '@/assets/icon-1.svg'
</script>
<template>
<component-a :img-src="imgSrcWithAlias" />
</template>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3713 次 |
最近记录: |