vue引入 图片的json文件 - 打包后图片不显示

 页面:

 <img :src="weatherDatas.imgPath">

 js:

//获取天气数据
getWeather(lon,lat){
   var that = this;

   //获取图片的json数组**
   var weatherImgData= require("../../assets/data/weather.json").data;

   this.$axios.get(httpcqpisa + "/cloud/meto/getWeatherDataList?areaCode="+this.areaCode+"&lat="+lat+"&lon="+lon)
   .then(res => {
      if(res.data && res.data.length){
         that.weatherDatas = res.data[0];
         weatherImgData.forEach(item => {
            if(that.weatherDatas.WEP == item.name){
               var str = '../../../static/image/weather/'+item.imgPath

               //获取图片路径****
               that.weatherDatas.imgPath = require( '../../../static/image/weather/'+item.imgPath);

              }
           })
        }
      }).catch(error => { console.log(error) });
    },

打包后的路径就对了 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 中,打包生成的静态资源文件列表可以通过 webpack 的插件 `webpack-manifest-plugin` 来生成。 首先,在项目中安装 `webpack-manifest-plugin`: ```bash npm install --save-dev webpack-manifest-plugin ``` 然后,在 webpack 的配置文件引入该插件,并配置输出的文件名: ```javascript const ManifestPlugin = require('webpack-manifest-plugin'); module.exports = { // ... plugins: [ new ManifestPlugin({ fileName: 'manifest.json', }), ], }; ``` 上述配置将在打包时生成一个名为 `manifest.json` 的文件,其中包含了所有打包生成的静态资源文件的信息。 如果你想要在 Vue 的模板中使用该文件列表,可以在 `index.html` 中通过 `script` 标签引入,然后在 Vue 实例中通过访问全局变量 `__webpack_manifest__` 来获取该文件列表。 ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>My App</title> </head> <body> <div id="app"></div> <script src="/dist/js/app.js"></script> <script src="/dist/manifest.json"></script> <script> var app = new Vue({ el: '#app', data: { manifest: __webpack_manifest__, }, }); </script> </body> </html> ``` 现在,你就可以在 Vue 实例中访问 `manifest` 对象来获取打包生成的静态资源文件列表了。例如,你可以遍历该列表,生成一组 `script` 或 `link` 标签来自动加载这些文件: ```html <div id="app"> <script v-for="file in manifest"> document.write('<script src="' + file.path + '"><\/script>'); </script> </div> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值