当前位置:网站首页>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)
},
边栏推荐
- 【无标题】
- Procédure de mesure du capteur d'accord vibrant par le module d'acquisition d'accord vibrant
- 通过js实现金字塔(星号金字塔,回文对称数字金字塔)
- ffmpeg常用命令(二)
- 【let var const】
- 大厂音视频职位面试题目--今日头条
- 为什么一定要从DevOps走向BizDevOps?
- Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
- mysql 报错 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
- IPv4 address, subnet mask, gateway
猜你喜欢
What is the essential difference between Bi development and report development?
118. Yanghui triangle
GC垃圾回收
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
Oracle physical architecture
P2433 【深基1-2】小学数学 N 合一
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, builds an open source ecological road
Axure does not display catalogs
Optaplanner learning notes (I) case cloud balance
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
随机推荐
win10下使用msys+vs2019编译ffmpeg源码
博途V16 获取系统时间转换成字符串
今日群里分享的面试题
CMU AI PhD first year summary
Brpc understanding
利用win7漏洞进行系统登录密码破解
Simplified pinduoduo product data
Uni app wechat applet one click login to obtain permission function
面试题 16.16. 部分排序-双指针法
OpenCV视频质量诊断----视频遮挡诊断
GB28181的NAT穿透
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached
118. Yanghui triangle
振弦采集模塊測量振弦傳感器的流程步驟
Collation of open source protocols of open source frameworks commonly used in Web Development
MySQL signale une erreur can 't create table' demo01. TB Étudiant '(errno: 150)
H264编码profile & level控制
MySQl的基本使用
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
2022/5/23-2022/5/30