当前位置:网站首页>Bind this of the current scope for callback functions in other cases such as timers and delayers
Bind this of the current scope for callback functions in other cases such as timers and delayers
2022-07-01 19:46:00 【Wang yuanrou】
List of articles
Front scene
mounted() {
console.log("this",this);
setTimeout(function() {
console.log("init",this);
},1000);
},

You want to access the current... In the callback function of the delayer Vue What about the instance ?
The way 1 Extra variable ( Not recommended )
mounted() {
console.log("this",this);
const that = this;
setTimeout(function() {
console.log("init",that);
},1000);
}

Extra variables created , It is not recommended to use .
The way 2 Arrow function
mounted() {
console.log("this",this);
setTimeout(
()=>{
console.log(" Arrow function ",this);
},
1000
);
},

Use the arrow function ,this Is in the parent scope this, At the same time, the arrow function arguments It is also in the parent scope arguments.
The way 3 Use bind
mounted() {
console.log("this",this);
setTimeout(function () {
console.log("bind",this);
}.bind(this),1000)
},

边栏推荐
- SQL 入门计划-1-选择
- MySQL signale une erreur can 't create table' demo01. TB Étudiant '(errno: 150)
- 采集抖音视频
- 利用win7漏洞进行系统登录密码破解
- [research materials] national second-hand housing market monthly report January 2022 - Download attached
- HLS4ML进入方法
- CMU AI PhD first year summary
- Oracle物理体系结构
- Image acquisition and playback of coaxpress high speed camera based on pxie interface
- brpc理解
猜你喜欢

Oracle physical architecture
![[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached](/img/c8/a205ddc2835c87efa38808cf31f59e.jpg)
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached

DDR4 test-2
![[research materials] Huawei Technology ICT 2021: at the beginning of the](/img/83/f21f148103815691796f87a95c687f.jpg)
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached

实例讲解将Graph Explorer搬上JupyterLab
![P2433 [deep foundation 1-2] primary school mathematics n in one](/img/28/e5eab8927694ea002b536202a1b5ea.png)
P2433 [deep foundation 1-2] primary school mathematics n in one

毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?

Object creation

servlet知识点

What is the essential difference between Bi development and report development?
随机推荐
IPv4 address, subnet mask, gateway
Linux下安装Redis,并配置环境
Wireshark packet analysis TCP, FTP
PowerDesigner设计Name和Comment 替换
New window open page -window open
JS 之 常用内置类的使用
118. 杨辉三角
Redo和Undo的区别
一文读懂C语言中的结构体
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
How to use console Log print text?
【sql优化】with as 和 临时表的区别
Using win7 vulnerability to crack the system login password
Compile ffmpeg source code with msys+vs2019 under win10
Optimization of video streaming with repeated requests in the case of unstable easygbs network
tensorflow报错Could not load dynamic library ‘libcudnn.so.8
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
【AI服务器搭建】CUDA环境