The Vue Cli3.0 event binding arrow function failed to get the this correctly

template code

methods:{
        onMouseDown:(e)=>{
            let count = 0;
            this.inDragging = true;//this
            window.addEventListener("mousemove",this.onDragging);
        },
}
Feb.24,2022

you can print the this pointing. Methods clearly written on the official website is not recommended to use the arrow function


reason: the pointing mechanism of the this of the arrow function

solution: do not use the arrow function

    onMouseDown(e) {
        let count = 0;
        this.inDragging = true; 
        window.addEventListener('mousemove',this.onDragging);
    },

The scope of this in the

arrow function is in parentheses,
solution:
1. Do not use the arrow function
2. Keep this outside the function


, .

methods:{
    onMouseDown(e){
        let count = 0;
        this.inDragging = true;//this
        window.addEventListener('mousemove',this.onDragging);
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf3182-54aac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf3182-54aac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?