這篇文章給大家介紹vue-resourse中怎么輸出json數(shù)據(jù),內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
創(chuàng)新互聯(lián)建站專注于克井企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站建設(shè)。克井網(wǎng)站建設(shè)公司,為克井等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)
1.demo目錄,不要管index.html和index.js
2.html頁(yè)面 vue-resourse-josn1.1.html展示json中的數(shù)據(jù)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>vue-resourse-json</title> </head> <body> <div id="app"> <ul> <li v-for="item in itemList" :id="item.id" > 編號(hào):{{item.id}}</br> 作者:{{item.author}}</br> 書(shū)名{{item.name}}</br> 價(jià)格:{{item.price}}</br> 出版時(shí)間{{item.time}}</br> </li> </ul> </div> <script src="static/js/libs/vue.js"></script> <script src="static/js/libs/vue-resource.min.js"></script> <script type="text/javascript" src="static/js/vue-resourse-json.js"></script> </body> </html>
3.js vue-resourse-json.js
var app = new Vue({ el:"#app", data:{ //聲明空數(shù)組,進(jìn)行數(shù)據(jù)接收,最后傳遞到前端頁(yè)面 itemList:[], }, //向data數(shù)組里添加數(shù)據(jù) mounted:function(){ this.getData(); }, methods: { getData:function () { var self = this; this.$http.get("static/data/list_json.json").then(function (res) { console.log(res); //var lens = res.body.lists.length; //console.log(lens); //獲取了當(dāng)前數(shù)組的長(zhǎng)度,為3 for(var i= 0,len=res.body.lists.length;i<len;i++){ //已經(jīng)獲取json數(shù)組中的數(shù)據(jù),接下來(lái)如何傳遞到前端頁(yè)面中 //獲取全部數(shù)據(jù) var selData = res.body.lists[i]; //console.log(selData); //獲取數(shù)組中的部分?jǐn)?shù)據(jù) var part = res.body.lists[i].name; //console.log(part); //將獲取的數(shù)據(jù)push到空的數(shù)組中itenList, self.itemList.push(selData); } }) } } });
4.json為list_josn.json
下面是json中的數(shù)據(jù)
{ "lists":[ { "id":"1", "author":"小華", "name":"《春天來(lái)了》", "price":"23", "time":"1998-03-12" }, { "id":"2", "author":"老舍", "name":"《濟(jì)南的冬天》", "price":"32", "time":"1956-12-09" }, { "id":"3", "author":"朱自清", "name":"《背影》", "price":"40", "time":"1943-09-12" } ] }
5.結(jié)果輸出
關(guān)于vue-resourse中怎么輸出json數(shù)據(jù)就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
標(biāo)題名稱:vue-resourse中怎么輸出json數(shù)據(jù)
URL地址:http://aaarwkj.com/article26/peshcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站排名、外貿(mào)建站、商城網(wǎng)站、品牌網(wǎng)站建設(shè)、App開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)