Vue-loader: v-bind:src Doesn't respect webpack aliases

Created on 19 Jul 2017  路  3Comments  路  Source: vuejs/vue-loader

Version

12.2.2

Reproduction link

Can't reproduce online. (webpack needed)

Steps to reproduce

  1. Using webpack, create an alias @ to a specific directory. (like an assets folder)
  2. 2.
<template>
  <img v-bind:src="foo">
</template>

<script>
export default {
  data () {
    return { foo: '~@/somePic.png' }
  }
}
</script>

Above doesn't work. The image is not displayed.

<template>
  <img src="~@/somePic.png">
</template>

However, this works perfectly.

What is expected?

The image source path to be replaced with the variable stored with vue ("~@/somePic.png") and parsed using webpack.

<img v-bind:src="foo">
into
<img v-bind:src="path/to/assets/somePic.png">

What is actually happening?

The image source is left exactly with the variable stored in vue and not parsed with webpack.

<img v-bind:src="foo">
into
<img v-bind:src="~@/somePic.png"> (and not parsed by webpack)

Most helpful comment

I see, that makes sense. Apparently the alternative method for this was to just wrap the aliased file path in require like require('~@/somePic.png')

All 3 comments

I meet this problem , too.

It can't, expression inside v-bind is executed in runtime, webpack aliases work in compile time.

I see, that makes sense. Apparently the alternative method for this was to just wrap the aliased file path in require like require('~@/somePic.png')

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sdvcrx picture sdvcrx  路  3Comments

frangio picture frangio  路  3Comments

snoopdouglas picture snoopdouglas  路  3Comments

githoniel picture githoniel  路  3Comments

banrikun picture banrikun  路  4Comments