這篇文章給大家分享的是有關(guān)vue如何實(shí)現(xiàn)點(diǎn)擊關(guān)注后及時(shí)更新列表功能的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來(lái)看看吧。
為江州等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及江州網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站制作、做網(wǎng)站、江州網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!vue是什么Vue是一套用于構(gòu)建用戶界面的漸進(jìn)式JavaScript框架,Vue與其它大型框架的區(qū)別是,使用Vue可以自底向上逐層應(yīng)用,其核心庫(kù)只關(guān)注視圖層,方便與第三方庫(kù)和項(xiàng)目整合,且使用Vue可以采用單文件組件和Vue生態(tài)系統(tǒng)支持的庫(kù)開發(fā)復(fù)雜的單頁(yè)應(yīng)用。
如圖,我要實(shí)現(xiàn)點(diǎn)擊關(guān)注之后列表及時(shí)更新成最新的列表。
思路很簡(jiǎn)單,主要是兩點(diǎn):
1、在點(diǎn)擊關(guān)注之后去執(zhí)行一個(gè)請(qǐng)求新的關(guān)注列表的action;
2、在vue組件中watch監(jiān)聽已關(guān)注列表和推薦關(guān)注列表
主要代碼如下:
組件:
關(guān)注的methods:
followMethod(item){ if(this.token){ this.$store.dispatch('follow',{followUserId:item.pubId,page:this.page,size:this.size}); this.$set(item,"followStatus",true); // this.$store.dispatch('refreshFollowList',{page:0,size:this.size}); }else{ Toast({ message: "請(qǐng)先登錄", duration: 800 }); setTimeout(function () { this.$router.push('/login'); },800) } },
watch:
followList(curVal, oldVal){ console.log(curVal) }, userFollowList(curVal, oldVal){ console.log(curVal) },
followList.js vuex的列表module文件:
action:
follow({dispatch,commit},payload){ axios({ method:"post", url:"web/follow/add", headers: {'w-auth-token': Cookies.get('token')}, params:{ page:payload.page, size:payload.size }, data:{ followUserId:payload.followUserId } }).then((res) => { Toast("關(guān)注成功"); return dispatch('refreshFollowList') }).catch((error) => { Toast("關(guān)注出錯(cuò),請(qǐng)重試!"); }); } refreshFollowList({state,commit}){ if(token){ axios.all([ axios({ method:"get", url:"web/pub/recommend", headers: {'w-auth-token': token}, }), axios({ method:"get", url:"web/pub/list_pub_and_top_news", headers: {'w-auth-token': Cookies.get('token')}, }) ]).then(axios.spread(function(res1,res2){ commit("REFRESHFOLLOWLIST",res1); commit("REFRESHUSERFOLLOWLIST",res2); })); }else{ axios({ method:"get", url:"web/pub/recommend", }).then(function(res){ commit("REFRESHFOLLOWLIST",res); }); } },
mutation:
const mutations = { REFRESHFOLLOWLIST(state,res){ state.followList=res.data.content; state.totalPages=res.data.totalPages; }, REFRESHUSERFOLLOWLIST(state,res){ state.userFollowList=res.data.content; state.userTotalPages=res.data.userTotalPages; }, };
感謝各位的閱讀!關(guān)于“vue如何實(shí)現(xiàn)點(diǎn)擊關(guān)注后及時(shí)更新列表功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
網(wǎng)頁(yè)名稱:vue如何實(shí)現(xiàn)點(diǎn)擊關(guān)注后及時(shí)更新列表功能-創(chuàng)新互聯(lián)
文章來(lái)源:http://aaarwkj.com/article42/cogdhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、關(guān)鍵詞優(yōu)化、網(wǎng)站制作、域名注冊(cè)、虛擬主機(jī)、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(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)
猜你還喜歡下面的內(nèi)容
移動(dòng)網(wǎng)站建設(shè)知識(shí)