日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 Vue 正文

vue異步請求數據重新渲染方式_vue.js

作者:渣渣前端 ? 更新時間: 2022-04-06 Vue

vue異步請求數據重新渲染

vue異步請求數據時往往不能及時更新,

下面介紹一種方法解決

export default {
? ? ? ? name: "pic",
? ? ? ? created() {
? ? ? ? ? ?this.getList();
? ? ? ? },
? ? ? ? data(){
? ? ? ? ? ? return{num:[]}
? ? ? ? },
? ? ? ? methods:{
? ? ? ? ? ? getList(){
? ? ? ? ? ? ? ? fetch('https://localhost:3000/get-banner-list').then(data=>{
? ? ? ? ? ? ? ? ? ? return data.json()
? ? ? ? ? ? ? ? }).then((data)=>{this.num=data.data;console.log(this.num)})
? ? ? ? ? ? }
? ? ? ? }
? ? }

這個時候template標簽里面的數據還沒有更新,所以可以這樣

<div class="propagate" v-show="num.length>0">
? ? ? ? <ul>
? ? ? ? ? ?<li ?v-for="(item,index) in num" :key="index">
? ? ? ? ? ? ? <img :src="item.photo_url" :key="index">
? ? ? ? ? ?</li>
? ? ? ? </ul>
? ? </div>

等數據加載完再顯示

自定義組件異步獲取數據重新渲染

視圖層

<myCard v-if="countView" icon="icon-yonghuzu" bgcolor="#2d8cf0" :count="homeData.govtCount" title="標題名稱"></myCard>

邏輯層

data(){
?? ?return {
?? ??? ??? ?countView:true
?? ??? ?}
?? ?}
//重新渲染組件
? ? ? ? _this.countView=false
? ? ? ? _this.$nextTick(()=>{
? ? ? ? ? ? _this.countView=true
? ? ? ? })

原文鏈接:https://blog.csdn.net/dtbk123/article/details/98888577

欄目分類
最近更新