浅谈vue的踩坑路

发布时间:2020-09-08 04:15:49 作者:PeggyChan
来源:脚本之家 阅读:129

------>axios模拟get json一直拿不到文件,先把data放到根目录,再去dev-server.js(就是npm执行的那个文件)里面设置静态资源访问路径app.use('/data',express.static('./data'))

...
app.use(hotMiddleware)

// serve pure static assets
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
app.use(staticPath, express.static('./static'))

app.use('/data',express.static('./data'))/*其实只有这一行,特别注意,这个不加拿不到json*/

var uri = 'http://localhost:' + port
...

------->拿不到图片,因为webpack打包后文件的名字可能会改变,so要看webpack的配置文件

{
  test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  loader: 'url-loader',
  options: {
   limit: 10000,
   /* name: utils.assetsPath('img/[name].[hash:7].[ext]')这个会改变图片的名字*/
     name: utils.assetsPath('img/[name].[ext]')
     }<br>}

------->数据里面的值有一些有有一些没有,如下这种

 [{
 "gname":"小米MIX3",
 "price":"3499",
 "img":"http://localhost:8082/static/img/mix5.png",
 "goods_des":"OLED 显示屏幕,升级计步算法",
 "review":"听说小米客服美眉很厉害送我一首藏头诗可好我爱钱天玉",
 "review_author":"来自橙子的"
},{
 "gname":"小米MIX4",
 "price":"3499",
 "img":"http://localhost:8082/static/img/mix5.png",
 "goods_des":"6.4 全面屏,全陶瓷机身"
}]

好,for循环的时候就要在相应的地方加上判断

<li v-for="(item,index) in arrList" class="goods-list-item">
 <span class="flag flag-new">{{item.flag}}</span>
 <a href="#" rel="external nofollow" class="img-wrap">
  <img :src="item.img" /><!--或者v-bind:src="item.img"-->
 </a>
 <h4 class="good-title"><a href="">{{item.gname}}</a></h4>
 <p class="good-desc">{{item.goods_des}}</p>
 <p class="good-price">{{item.price}}</p>
 <p class="review-wrap" v-if="item.review"><!--如果review存在就显示-->
  <a href="">
   <span class="review">{{item.review}}</span>
   <span class="author">{{item.review_author}}</span>
  </a>
 </p>
</li>

以上这篇浅谈vue的踩坑路就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。

推荐阅读:
  1. ingress rollingUpdate 踩坑记录
  2. 在soapui上踩过的坑

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue 踩坑 ue

上一篇:关于nginx日志增加cookie信息

下一篇:在Vue项目中取消ESLint代码检测的步骤讲解

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》