網站首頁 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
相關推薦
- 2022-07-03 C語言由淺入深了解變量的應用_C 語言
- 2023-01-02 Oracle中sql語句如何執行日志查詢_MsSql
- 2022-08-01 GO項目配置與使用的方法步驟_Golang
- 2022-09-11 Shell之免交互的實現_linux shell
- 2022-06-24 Python+matplotlib實現簡單曲線的繪制_python
- 2023-01-19 python使用?f?格式化字符串的用法_python
- 2022-03-26 Postman配置多環境請求地址的實現_相關技巧
- 2022-11-15 python重用父類功能的兩種方式實例詳解_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支