zoukankan      html  css  js  c++  java
  • vue的踩坑路

    ------>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]')
         }
    }

      

    ------->数据里面的值有一些有有一些没有,如下这种
      [{
      "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="#" class="img-wrap"> <img :src="item.img" /><!--或者v-bind:src="item.img"--> </a> <h3 class="good-title"><a href="">{{item.gname}}</a></h3> <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>
  • 相关阅读:
    JVM(随手笔记)
    linux常用操作(个人笔记)
    MySQL学习笔记(个人随手笔记)
    jquery对象和Dom对象的转化([0])
    函数防抖和函数节流
    数据持久化分析
    day.js处理相对时间
    外链资源403的处理
    前端实现图片预览的两种方式及使用
    监听器标准写法
  • 原文地址:https://www.cnblogs.com/PeggyChan/p/7454725.html
Copyright © 2011-2022 走看看