vue.js配合$.post從后臺獲取數(shù)據(jù)簡單demo分享
首先導(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標簽與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"> <h2>{{item.title}}</h2> <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對象
當然 官網(wǎng)上推薦的是使用axios npm這種方式。
以上這篇vue.js配合$.post從后臺獲取數(shù)據(jù)簡單demo就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue頁面不能根據(jù)路徑進行跳轉(zhuǎn)的解決方法
本文主要介紹了vue頁面不能根據(jù)路徑進行跳轉(zhuǎn)的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-12-12vue-router相關(guān)基礎(chǔ)知識及工作原理
這篇文章主要介紹了vue-router相關(guān)基礎(chǔ)知識及單頁面應(yīng)用的工作原理,需要的朋友可以參考下2018-03-03如何使用VuePress搭建一個類型element ui文檔
這篇文章主要介紹了如何使用VuePress搭建一個類型element ui文檔,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-02-02搭建vue3項目以及按需引入element-ui框架組件全過程
element是基于vue.js框架開發(fā)的快速搭建前端的UI框架,下面這篇文章主要給大家介紹了關(guān)于搭建vue3項目以及按需引入element-ui框架組件的相關(guān)資料,文中通過圖文以及代碼介紹的非常詳細,需要的朋友可以參考下2024-02-02vue新建環(huán)境變量以及網(wǎng)絡(luò)請求工具axios的二次封裝詳解
這篇文章主要為大家介紹了vue新建環(huán)境變量以及網(wǎng)絡(luò)請求工具axios的二次封裝詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06