Vue-cli: Resolve asset in <a> href (like <img> src)

Created on 15 May 2018  路  3Comments  路  Source: vuejs/vue-cli

What problem does this feature solve?

Allows linking to assets without using /public folder.

What does the proposed API look like?

<a href="../assets/logo.png">
  <img src="../assets/logo.png">
</a>

Results in:

<a href="../assets/logo.png">
  <img src="/img/logo.4f17609b.png">
</a>

Should result in:

<a href="/img/logo.4f17609b.png">
  <img src="/img/logo.4f17609b.png">
</a>

Most helpful comment

Use require to use the webpack loaders:

<a :href="require('../assets/logo.png')">

All 3 comments

Use require to use the webpack loaders:

<a :href="require('../assets/logo.png')">

https://vue-loader.vuejs.org/options.html#transformasseturls

@yyx990803 how to change these in vue.config.js please advice. I am new to vue.

Was this page helpful?
0 / 5 - 0 ratings