亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue-resourse將json數(shù)據(jù)輸出實(shí)例

 更新時(shí)間:2017年03月08日 15:55:15   作者:gz_blog  
這篇文章主要為大家詳細(xì)介紹了vue-resourse將json數(shù)據(jù)輸出實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文主要講v-resourse 獲取json數(shù)據(jù)并傳遞到DOM中,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

1.demo目錄,不要管index.html和index.js

2.html頁面 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" style="list-style-type: none;">

編號(hào):{{item.id}}</br>
作者:{{item.author}}</br>
書名{{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ù)接收,最后傳遞到前端頁面
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ù),接下來如何傳遞到前端頁面中
//獲取全部數(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":"《春天來了》",
"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é)果輸出

6.總結(jié):主要理清數(shù)據(jù)請(qǐng)求和傳遞的流程就行了。

本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。

關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。

更多vue學(xué)習(xí)教程請(qǐng)閱讀專題《vue實(shí)戰(zhàn)教程》

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論