淺談vue的踩坑路
更新時間:2017年08月31日 08:44:38 作者:PeggyChan
下面小編就為大家?guī)硪黄獪\談vue的踩坑路。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
------>axios模擬get json一直拿不到文件,先把data放到根目錄,再去dev-server.js(就是npm執(zhí)行的那個文件)里面設置靜態(tài)資源訪問路徑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>}
------->數(shù)據(jù)里面的值有一些有有一些沒有,如下這種
[{ "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循環(huán)的時候就要在相應的地方加上判斷
<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> <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>
以上這篇淺談vue的踩坑路就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue+ElementUI實現(xiàn)訂單頁動態(tài)添加產(chǎn)品數(shù)據(jù)效果實例代碼
本篇文章主要介紹了vue+ElementUI實現(xiàn)訂單頁動態(tài)添加產(chǎn)品效果實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07