Closed alephpi closed 8 months ago
have you tried to import the asset import bgImgUrl from '../assets/wallpaper/default.png?url
? https://vitejs.dev/guide/assets.html#explicit-url-imports
have you tried to import the asset
import bgImgUrl from '../assets/wallpaper/default.png?url
? https://vitejs.dev/guide/assets.html#explicit-url-imports
Not yet. But what I want is let bgImgUrl
be a reactive variable (which can be modified), so that we can change the background image among multiple images in the wallpaper folder.
Or maybe I just import all the images directly and make an url dictionary? That way kinds of verbose since the wallpaper is really numerous.
Update: I tried direct import with background-image: url(--bgImgUrl)
and background-image: v-bind(bgImgUrl)
, but still neither of them works.
direct assignment:
binding:
seems that when binding it just cannot resolve the relative path
current workaround: create static css rules for background-image, bind the css class to title
. Seems the problem is the relative url resolution.
Dynamic variables won't work with imports/urls. Rollup needs to be able analyze them statically at build level to emit assets. It'd work if assets are in public directory. We can't fix this here.
Discussed in https://github.com/vuejs/vitepress/discussions/2471