here is the code:
<template>
<div id="app">
<button
@click="() => this.search()"
>btn1</button>
<button
@click="() => this.search1()"
>btn2</button>
</div>
</template>
<script>
export default {
name: "App",
methods: {
search: () => {
console.log(this);
//debugger
},
search1: function() {
console.log(this);
//debugger
},
},
};
</script>
when I click 'btn1' , the console show "undefined".
when click 'btn2', the console show vuecomponent.
I'm so confuse why 'this' is undefined?
Then I found stranger thing,
when use debugger for breakpoint debugging where the console prints ‘undefined’
I can see the value of ‘this’ again. Why?
see: