为了账号安全,请及时绑定邮箱和手机立即绑定

webpack 如何处理通过 `js` 引入的资源文件加载问题??

webpack 如何处理通过 `js` 引入的资源文件加载问题??

MMMHUHU 2018-08-26 15:10:22
相关配置:项目路径:/var/website/test 目录结构: compiled source     components        public             public.vue    static         image             test.png     plugins    // ...static假设在一个 source/components/public/public.vue 文件中,通过 js 引入了一个文件:<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 打包后,访问不到资源!!webpack 如何处理通过 js 引入的资源文件加载问题??
查看完整描述

2 回答

?
翻阅古今

TA贡献1780条经验 获得超5个赞

import再使用

import src from '../../static/image/test.png';export default {
  name: '',
  mounted() {    this.$refs.test.src = src;
  }
};


查看完整回答
反对 回复 2018-08-27
?
30秒到达战场

TA贡献1828条经验 获得超6个赞

webpack引入图片等其他资源也必须是require或者import(最终也会转成require)

查看完整回答
反对 回复 2018-08-27
  • 2 回答
  • 0 关注
  • 928 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信