在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ webpack 如何處理通過(guò) `js` 引入的資源文件加載問(wèn)題??

webpack 如何處理通過(guò) `js` 引入的資源文件加載問(wèn)題??

相關(guān)配置:

項(xiàng)目路徑:/var/website/test
目錄結(jié)構(gòu):
compiled
source
    components
        public
            public.vue
    static
        image
            test.png
    plugins
    // ...
static

假設(shè)在一個(gè) source/components/public/public.vue 文件中,通過(guò) js 引入了一個(gè)文件:

<template>
    <section>
        <img ref='test' src='' class='image'>
    </section>
</template>
<script>
export default {
    name: '' , 
    mounted () {
        this.$refs.test.src='../../static/image/test.png';
    }
};
</script>

webpack 打包后,訪問(wèn)不到資源??!

webpack 如何處理通過(guò) js 引入的資源文件加載問(wèn)題??

回答
編輯回答
網(wǎng)妓

webpack引入圖片等其他資源也必須是require或者import(最終也會(huì)轉(zhuǎn)成require)

2018年6月21日 02:27
編輯回答
糖豆豆

import再使用

import src from '../../static/image/test.png';

export default {
  name: '',
  mounted() {
    this.$refs.test.src = src;
  }
};
2017年9月13日 23:26