您好,登錄后才能下訂單哦!
首先導(dǎo)入
<script type="text/javascript" src="/island/stage/js/vue.min.js"></script>
html樣式:
<div id="main-content" class="wrap-container zerogrid"> <article id="news_content" v-for="item in items"> <div class="col-1-2 right"> <img :src="item.coverimage"/><!--img標(biāo)簽與src之間需要有空格--> </div> <div class="col-1-2 left"> <a class="art-category left" href="#" rel="external nofollow" rel="external nofollow" >{{item.releasetime}}</a> <div class="clear"></div> <div class="art-content"> <h3>{{item.title}}</h3> <div class="info"> <a href="#" rel="external nofollow" rel="external nofollow" >{{item.author}}</a> </div> <div class="line"></div> <p>{{item.content}}</p> <a v-bind:href="['/island/stage/newscontent.html?id='+item.id]" rel="external nofollow" class="more">閱讀全文</a> <!--屬性數(shù)據(jù)綁定以及拼接--> </div> </div> </article> <!-- 循環(huán)結(jié)束(新聞) --> </div>
js部分:
var vm = new Vue({ el: '#main-content', data: { items : [] }, //end data created:function(){ $.post("/island/stage/queryOneAllNews.do",{"categoryid":parseInt(categoryid)},function(data){ vm.items = data; });//end post } //created }); //end vue
注意:返回的json數(shù)組 并不需要JSON.stringify(data) 轉(zhuǎn)成json字符串 items 這里需要的是json對(duì)象
當(dāng)然 官網(wǎng)上推薦的是使用axios npm這種方式。
以上這篇vue.js配合$.post從后臺(tái)獲取數(shù)據(jù)簡(jiǎn)單demo就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。