1

In Vue, I'm trying to pass a string into require(), the first option works (passing the string directly). however when passing the variable containing the string the loading fails, any clues???

<template>
    <img :src="require('@/assets/channels/email.png')" />
//   <img :src="require(test)" />
</template>

export default {
  data() {
    return {
      test: "@/assets/channels/email.png"
    };
  }
}
1

1 Answer 1

0

Maximum you could is a require with expression, with full variable it wont work. See docs here

<template>
    <img :src="require('@/assets/channels/'+test+'.png')" />
</template>

export default {
  data() {
    return {
      test: "email"
    };
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Mmm... care to fix typo / explain why it won't work?

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.