溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

vue.js配合$.post從后臺(tái)獲取數(shù)據(jù)簡(jiǎn)單demo分享

發(fā)布時(shí)間:2020-10-14 18:32:28 來源:腳本之家 閱讀:225 作者:Islandww 欄目:web開發(fā)

首先導(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è)參考,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(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)容。

AI