------>axios模擬get json一直拿不到文件,先把data放到根目錄,再去dev-server.js(就是npm執(zhí)行的那個(gè)文件)里面設(shè)置靜態(tài)資源訪問(wèn)路徑app.use('/data',express.static('./data'))
...app.use(hotMiddleware)// serve pure static assetsvar staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)app.use(staticPath, express.static('./static'))app.use('/data',express.static('./data'))/*其實(shí)只有這一行,特別注意,這個(gè)不加拿不到j(luò)son*/var uri = 'http://localhost:' + port...
------->拿不到圖片,因?yàn)閣ebpack打包后文件的名字可能會(huì)改變,so要看webpack的配置文件
{ test: //.(png|jpe?g|gif|svg)(/?.*)?$/, loader: 'url-loader', options: { limit: 10000, /* name: utils.assetsPath('img/[name].[hash:7].[ext]')這個(gè)會(huì)改變圖片的名字*/ name: utils.assetsPath('img/[name].[ext]') }<br>}
------->數(shù)據(jù)里面的值有一些有有一些沒(méi)有,如下這種
[{ "gname":"小米MIX3", "price":"3499", "img":"http://localhost:8082/static/img/mix5.png", "goods_des":"OLED 顯示屏幕,升級(jí)計(jì)步算法", "review":"聽(tīng)說(shuō)小米客服美眉很厲害送我一首藏頭詩(shī)可好我愛(ài)錢(qián)天玉", "review_author":"來(lái)自橙子的"},{ "gname":"小米MIX4", "price":"3499", "img":"http://localhost:8082/static/img/mix5.png", "goods_des":"6.4 全面屏,全陶瓷機(jī)身"}]
好,for循環(huán)的時(shí)候就要在相應(yīng)的地方加上判斷
<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的踩坑路就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注