如图,我要实现点击关注之后列表及时更新成最新的列表。
思路很简单,主要是两点:
1、在点击关注之后去执行一个请求新的关注列表的action;
2、在vue组件中watch监听已关注列表和推荐关注列表
主要代码如下:
组件:
关注的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: "请先登录", 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("关注成功"); return dispatch('refreshFollowList') }).catch((error) => { Toast("关注出错,请重试!"); }); } 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; }, };
总结
以上所述是小编给大家介绍的vue实现点击关注后及时更新列表功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 金池刘罡《昨日情歌HQ》头版限量编号[低速原抓WAV+CUE]
- 段奥娟.2024-23·岁碎念【白米范】【FLAC分轨】
- 顺子.2001-昨日·唯一·更多·顺子自选辑【魔岩】【WAV+CUE】
- 无印良品.1999-私藏三首·原创相对论(EP)【滚石】【WAV+CUE】
- Merryland《Merryland》[FLAC/分轨][170.22MB]
- 庄锭欣 ELKIE《没有你的未来》[320K/MP3][15.78MB]
- 庄锭欣 ELKIE《没有你的未来》[FLAC/分轨][36MB]
- TchaikovskySwanLake,Op.20柴可夫斯基天鹅湖(2013)SACD[Hi-Res]
- 24bit达人艺典《琴歌终极版》整轨WAV+CUE
- 黑鸭子.2005-《发烧DSD》柏菲[WAV分轨]
- 群星.1990-电影看板·人间道【宝丽金】【WAV+CUE】
- 周殷廷.2024-TO.WHOM.IT.MAY.CONCERN【环球】【FLAC分轨】
- 草蜢.1997-三人世界精选17首【宝丽金】【WAV+CUE】
- 【古琴音乐】管平湖《广陵散》2004[FLAC+CUE]
- 【中国民乐】《少数民族器乐·苗岭的早晨》2004[WAV+CUE]