scope of this keyword in vue js

Solutions on MaxInterview for scope of this keyword in vue js by the best coders in the world

showing results for - "scope of this keyword in vue js"
Romain
06 Jun 2018
1<script>
2export default {
3    mounted() {
4        this.myMethod()
5    },
6    methods:{
7        myMethod() {
8            let _this = this
9            let self = this
10            let that = this
11            window.addEventListener('click', function() {
12                console.log('this scope (function) >', this)
13                console.log('this scope (vuejs) >', _this)
14                console.log('this scope (vuejs) >', self)
15                console.log('this scope (vuejs) >', that)
16            })
17        }
18    }
19}
20</script>
21
Mads
13 Jan 2019
1<script>
2export default {
3    data:() => ({
4        myData: 1
5    }),
6    mounted() {
7        this.myMethod()
8    },
9    methods:{
10        myMethod() {
11            window.addEventListener('click', () => {
12                console.log('this >', this.myData)
13            })
14        }
15    }
16}
17</script>
18