1

I tried to render image in my website that made with vue.js

the file i want is here D:\programing\mr_dan\assets\img\bkgds\cheesecloth-herbs-bk.jpg

and component of vue in D:\programing\mr_dan\src\components\Home.vue

this the code of home.vue

<div style="background-image:url(../../assets/img/bkgds/cheesecloth-herbs-bk.jpg);">
1
  • provide more information. are you using any build tool like webpack or running vue in a static html page? Commented Apr 9, 2018 at 18:34

1 Answer 1

0

Vue cli's WebPack is probably not parsing that content as an asset. One workaround is to use require():

<div :style="'background-image:url(' + require('../../assets/img/bkgds/cheesecloth-herbs-bk.jpg') + ');'">

Check a demo CodeSandbox here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.