浅谈vue异步数据影响页面渲染
作者:zjr11111 时间:2024-04-30 10:45:19
今天遇到一个问题,要保证页面渲染前请求的数据已经得到了
由于user是在异步请求之后保存在session中,而在页面渲染时session中还没有user,页面直接报错。
因此我希望能在所有请求都得到后再去做页面的渲染。
1.先把id为app的div用v-if="appShow",定义appShow为false进行隐藏,避免渲染
2.写计数器,每1ms进行一次查询,如果session中已经有user,删除过滤器,移除滤布,appShow为true,开始渲染页面,这样可以保证页面的正常渲染。
具体代码如下:
created:function (){
let that = this
let timeTerval = setInterval(()=>{
if(sessionStorage.user){
clearInterval(timeTerval);
that.appShow = true;//渲染app
var removeLoad = document.getElementById("loading")
removeLoad.style.display = "none"
}else{
console.log("1222")
}}, 1);
},
来源:https://blog.csdn.net/weixin_39308542/article/details/93062240
标签:vue,异步,页面,渲染
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
layui表单提交到后台自动封装到实体类的方法
2024-04-22 22:33:11
![](https://img.aspxhome.com/file/2023/8/135648_0s.jpg)
django数据模型on_delete, db_constraint的使用详解
2023-02-16 04:48:06
SQL Server 2012 安装图解教程(附sql2012下载地址)
2024-01-18 20:49:32
![](https://img.aspxhome.com/file/2023/5/84345_0s.jpg)
Python如何提取csv数据并筛选指定条件数据详解
2022-07-20 22:47:59
![](https://img.aspxhome.com/file/2023/0/94060_0s.png)
在IE中使用高级CSS3选择器
2010-01-22 15:20:00
什么是XML?
2007-10-29 12:53:00
YOLOv5改进之添加CBAM注意力机制的方法
2023-07-22 20:48:52
![](https://img.aspxhome.com/file/2023/6/61696_0s.png)
python可视化之颜色映射详解
2021-01-27 01:23:52
![](https://img.aspxhome.com/file/2023/6/109326_0s.jpg)
使用Python制作微信跳一跳辅助
2022-09-21 12:10:37
![](https://img.aspxhome.com/file/2023/6/121086_0s.png)
MediaPipe API实现骨骼识别功能分步讲解流程
2022-06-17 05:41:10
![](https://img.aspxhome.com/file/2023/5/112125_0s.png)
python基础之并发编程(二)
2023-01-16 03:10:37
pygame游戏之旅 添加游戏界面按键图形
2023-06-30 21:48:38
![](https://img.aspxhome.com/file/2023/4/87754_0s.jpg)
Sql server 2005 找出子表树
2008-11-24 15:23:00
php简单浏览目录内容的实现代码
2023-10-25 01:32:43
Go语言中调用外部命令的方法总结
2024-05-13 10:44:09
![](https://img.aspxhome.com/file/2023/8/125108_0s.png)
sqlserver 系统存储过程 中文说明
2024-01-18 12:22:14
详细介绍Python中的set集合
2023-07-26 07:35:03
padas 生成excel 增加sheet表的实例
2023-03-22 04:52:04
![](https://img.aspxhome.com/file/2023/2/118282_0s.jpg)
mybatis+mysql 使用存储过程生成流水号的实现代码
2024-01-18 11:09:56
![](https://img.aspxhome.com/file/2023/8/69838_0s.png)
php实现统计二进制中1的个数算法示例
2024-06-05 09:39:05
![](https://img.aspxhome.com/file/2023/5/122535_0s.png)