can I use vite alias in a vue function?

21 Views Asked by At

Using vue 3.4 and vite 5.1 and I have the standard alias set in my vite.config.ts

alias: {
    '@': fileURLToPath(new URL('./src', import.meta.url))
}

So far so good. Works beautifully. I can do this with no problem:

<img src="@/assets/images/image.jpg" alt='an image'>

and the image shows up just fine because it is in ./src/assets/images/image.jpg.

But what I want to do is set bind src to a computed ref since the image will change depending on what the user clicks. That doesn't seem to work though, even when the path is set correctly to "@/assets/images/image.jpg":

<img :src="myComputedRef" alt='an image'>
<img :src="myPathFunction()" alt='an image'>

Is this just a limitation of vite? I can see that, because otherwise it would constantly be parsing the files every time the dom changed.

0

There are 0 best solutions below