在vue组件中使用webpack别名

时间:2017-12-07 19:02:51

标签: webpack vue.js vue-component

如何在Vue组件中使用webpack别名?

例如,在显示组件时设置图像URL:

<template>
  <img src="~@/assets/placeholder.jpg" ref="image"> <!-- this image works -->
</template>

<script>
  export default {
    mounted() {
     const which = '1';  // this would presumably be dynamic
     this.$refs.image.src = `~@/assets/${which}-image.jpg`;  // doesn't work
    },
  };
</script>

0 个答案:

没有答案