当前位置:网站首页>Async await to achieve sleep waiting effect
Async await to achieve sleep waiting effect
2022-06-25 14:24:00 【Fat goose 68】
List of articles
One 、 Problem description
At work , The vehicles in the map need to follow GPS Move , This requires that the center point of the map is centered on the car , Call directly setCenter Change the position of the center point , When the screen is big , The user thinks it is dazzling , The best way is to use flyto function , Realize the translation and smooth movement of the map .
But earlier versions API There is no flyto, The solution is to split the current center point to the final center point into several nodes , Then refresh quickly , Realization Small step run , Improve user experience .
problem : Make sure that the split middle point can start the next center point only after the page is refreshed
Two 、 How to ensure the refresh order
The idea is to use sleep Thought , After rendering the current center point , That is, the next rendering , There is a time to wait for rendering , So you can control the rhythm by yourself .
Why choose aysnc and await Well ?
Use aysnc and await , To make full use of js The advantages of single threading , When other callback functions need to set the center point again , It must be done with the current logic , Then the next center point change will be performed , To ensure the Sequence of the whole line
3、 ... and 、Vue Code case
<template>
<div class>
<div id="hmap" style="height: 200px;width: 200px;">
{
{msg}}
</div>
</div>
</template>
<script> export default {
data () {
return {
msg: '' } }, mounted () {
this.sleepAction() }, methods: {
sleepAction () {
const MAX = 4 const betweenTime = 2000 const that = this for (let i = 1; i <= MAX; i++) {
// console.log(betweenTime * i) this.wait(betweenTime * i, function () {
console.log('111111111111111', betweenTime * i) that.msg = betweenTime * i }) } }, sleep2 (time) {
return new Promise((resolve) => {
setTimeout(resolve, time) }) }, // async await async wait (time, fun) {
await this.sleep2(time) if (fun) {
fun() } } } } </script>
<style lang="scss" scoped></style>
边栏推荐
- Sigmoid function sigmoid derivation
- Laravel8 implementation of picture verification code
- [untitled]
- 买基金在哪里开户安全?求指导
- One time summary: 64 common terms for data analysis!
- Two methods to rollback the code in pycharm to the specified version (with screenshot)
- shell 运算符
- 用NumPy实现神经网络(Mysteries of Neural Networks Part III)
- Network remote access using raspberry pie
- 算力&NFT交易平台F3.xyz旗下独家权益NFT项目Hash Eagle将盛大发行
猜你喜欢

K-line diagram 24 classic diagrams (shadow)

深入理解深度神经网络背后的数学(Mysteries of Neural Networks Part I)

shell 运算符

Share the code technology points and software usage of socket multi client communication

Shell operator
![[untitled]](/img/7f/e2c9fbfb5eb6e7fcc6e23a46540933.jpg)
[untitled]

分享自己平時使用的socket多客戶端通信的代碼技術點和軟件使用

shell 数组

使用调试工具调试博图TCP连接所遇到的问题

Page 112 machine learning - review of fundamentals of mathematics pptx
随机推荐
【世界历史】第二集——文明的曙光
深入理解深度神经网络背后的数学(Mysteries of Neural Networks Part I)
What are the red lines of open source that should not be trodden on?
如何在 2022 年为 Web 应用程序选择技术堆栈
Output 0 ~ n digits and output multiple times
英語中的九大詞性與九大時態
None of the MLIR Optimization Passes are enabled (registered 2)解决办法
一次性总结:64个数据分析常用术语!
TSDB在民机行业中的应用
[untitled]
oracle数据库常用的函数总结
Which is better and safer, GF easy gold rush or flush
API encapsulation of uniapp applet
Clinical Chemistry | 张建中/徐健开发幽门螺杆菌单细胞精准诊疗技术
程序员为什么要软一点?
Realization of neural networks with numpy
112页机器学习-数学基础回顾.pptx
Tencent cloud builds a Socks5 multi IP proxy server to realize the perfect building of a game with a single window and a single IP. Tutorial attached tool "suggestions collection"
让PyTorch训练速度更快,你需要掌握这17种方法
Kubernetes cluster construction of multiple ECS