简体   繁体   中英

handle data attributes with webpack and vuejs

I use the vue cli with webpack and I'm absolutely fine with it. But now I have a little problem!

I want that the path in the data attributes from the <object> tags are also compiled like the src attributes from the <img> tags

for example:

If I do something like this

<img src="../path/to/file.svg" alt="">

webpack compiled the path to

<img src="/dist/path/to/file.svg" alt="">

but when I do something like this:

<object type="image/svg+xml" data="../path/to/file.svg">fallback</object>

it doesn't work :(

Use the require() helper

Example:

<object :data="require(`../path/to/file-${if-you-need-to-pass-a-variable-here}.svg`)" type="image/svg+xml" >fallback</object>

<img :src="require(`../path/to/file-${if-you-need-to-pass-a-variable-here}.svg`)" alt="">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM