Vue如何獲取數(shù)據(jù)列表展示
這個(gè)例子從 Github 的 API 中獲取了最新的 Vue.js 提交數(shù)據(jù),并且以列表形式將它們展示了出來。你可以輕松地切換 master 和 dev 分支。
一、展示
二、源碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.7/dist/vue.js"></script> </head> <body> <div id="app"> <h2>title</h2> <template v-for="(branch, index) in branches"> <input type="radio" :id=index :value="branch" v-model="currentBranch" /> <label :for="index">{{ branch }}</label> </template> <div>當(dāng)前選定:{{ currentBranch }}</div> <ul> <li v-for="item in getData"> <a :href="item.html_url" rel="external nofollow" >{{ item.sha.slice(0, 7) }}</a> - <span>{{ item.commit.message }}</span><br/> <span>創(chuàng)建人:<a :href="item.author.html_url" > {{ item.commit.author.name }}</a></span><br/> <span>創(chuàng)建時(shí)間:{{ item.commit.author.date | formatDate }}</span> </li> </ul> </div> <script> let apiURL = 'https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha=' let vm = new Vue({ el: '#app', data() { return ({ branches: ['master', 'dev'], currentBranch: 'master', getData: null, }); }, created() { this.fetchDate(); }, watch: { currentBranch: 'fetchDate' }, filters: { formatDate(v) { return v.replace(/T|Z/g, ' '); } }, methods: { fetchDate() { var xhr; if(window.XMLHttpRequest) { xhr = new XMLHttpRequest(); }else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } let self = this; xhr.onload = function() { if(xhr.readyState == 4) { if(xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) { self.getData = JSON.parse(xhr.responseText); }else { console.error(xhr.status, xhr.statusText); } } } xhr.open('GET', apiURL + this.currentBranch); xhr.send(null); } }, }); </script> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)展示列表的數(shù)據(jù)
- vue?使用el-table循環(huán)輪播數(shù)據(jù)列表的實(shí)現(xiàn)
- vue實(shí)現(xiàn)動(dòng)態(tài)列表尾部添加數(shù)據(jù)執(zhí)行動(dòng)畫
- vue如何從后臺(tái)獲取數(shù)據(jù)生成動(dòng)態(tài)菜單列表
- Vue3 列表界面數(shù)據(jù)展示詳情
- 使用Vue3進(jìn)行數(shù)據(jù)綁定及顯示列表數(shù)據(jù)
- vue列表數(shù)據(jù)刪除后主動(dòng)刷新頁面及刷新方法詳解
- vue2.0實(shí)現(xiàn)列表數(shù)據(jù)增加和刪除
- vue input輸入框關(guān)鍵字篩選檢索列表數(shù)據(jù)展示
- vue父列表數(shù)據(jù)獲取子列表數(shù)據(jù)的實(shí)現(xiàn)步驟
相關(guān)文章
在antd中setFieldsValue和defaultVal的用法
這篇文章主要介紹了在antd中setFieldsValue和defaultVal的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-10-10vue對(duì)象添加屬性(key:value)、顯示和刪除屬性方式
這篇文章主要介紹了vue對(duì)象添加屬性(key:value)、顯示和刪除屬性方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07vue+elementUI實(shí)現(xiàn)內(nèi)嵌table的方法示例
本文主要介紹了vue+elementUI實(shí)現(xiàn)內(nèi)嵌table的方法示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12vue中使用jquery滑動(dòng)到頁面底部的實(shí)現(xiàn)方式
這篇文章主要介紹了vue中使用jquery滑動(dòng)到頁面底部的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12vuex實(shí)現(xiàn)簡(jiǎn)易計(jì)數(shù)器
這篇文章主要為大家詳細(xì)介紹了vuex實(shí)現(xiàn)一個(gè)簡(jiǎn)易計(jì)數(shù)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Vue3導(dǎo)航欄組件封裝實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了Vue3導(dǎo)航欄組件封裝的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09