Vue2.0中http請(qǐng)求以及l(fā)oading展示的示例分析

這篇文章主要為大家展示了“Vue2.0中http請(qǐng)求以及l(fā)oading展示的示例分析”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Vue2.0中http請(qǐng)求以及l(fā)oading展示的示例分析”這篇文章吧。

成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),墨竹工卡企業(yè)網(wǎng)站建設(shè),墨竹工卡品牌網(wǎng)站建設(shè),網(wǎng)站定制,墨竹工卡網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,墨竹工卡網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

我們需要額外兩個(gè)依賴vuex 和 axios:(還是接著上一個(gè)項(xiàng)目MyFirstProject寫)

npm i vuex axios -D

首先簡(jiǎn)單的闡述下http請(qǐng)求

1、main.js 中引入axios

import axios from 'axios' 
Vue.prototype.$http = axios;

2、focus.vue中寫個(gè)函數(shù)獲取數(shù)據(jù)

<template>
	<div id="focus">
		<ul >
			<li v-for="(item,index) in focusList">
				<div class="fportraits">
					<img :src="'./src/'+item.portrait" :alt="item.name">
				</div>
				<div class="details">
					<div class="ftitle"><strong> {{ item.name }} </strong></div>
					<p> {{ item.production }} </p>
				</div>
				<div class="isfocused">
					<p>取消關(guān)注</p>
				</div>
				<div class="clearfix"></div>
			</li>
		</ul>
	</div>
</template>
<script>
	export default{
		data(){
			return {
				focusList:[] //存儲(chǔ)請(qǐng)求返回的數(shù)據(jù)
			}
		},
		mounted(){
			this.getFocusList()
		},
		methods:{
			getFocusList(){   //http get請(qǐng)求data.json 的數(shù)據(jù)
				var vm = this;
				this.$http.get('src/assets/data/data.json')
					.then(function(res){
						vm.focusList = res.data;
					})
					.catch(function(err){
						console.log(err)
					})
			}
		}
	}
</script>
<style scoped>
#focus{text-align:left;}
#focus ul{margin:0 auto;width:50rem;border-bottom:none;}
#focus p{margin:0;}
#focus li{width:46rem;display:block;border-bottom:1px solid #ddd;padding:0.5rem 2rem;cursor:default;}
#focus img{height:4rem;margin-left:-1rem;}
.fportraits{float:left;width:4rem;height:4rem;border-radius:50%;overflow:hidden;}
.details{float:left;margin-left:1rem;}
.isfocused{float:right;font-size:0.8rem;height:0.8rem;line-height:0.8rem;margin:0;}
.clearfix{clear:both;}
</style>

獲取成功后展示效果如圖:

Vue2.0中http請(qǐng)求以及l(fā)oading展示的示例分析

以上是“Vue2.0中http請(qǐng)求以及l(fā)oading展示的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章名稱:Vue2.0中http請(qǐng)求以及l(fā)oading展示的示例分析
分享鏈接:http://bm7419.com/article38/jjecpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、用戶體驗(yàn)、自適應(yīng)網(wǎng)站微信公眾號(hào)、標(biāo)簽優(yōu)化、電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)