Answers for "scope of this keyword in vue js"

0

scope of this keyword in vue js

<script>
export default {
    mounted() {
        this.myMethod()
    },
    methods:{
        myMethod() {
            let _this = this
            let self = this
            let that = this
            window.addEventListener('click', function() {
                console.log('this scope (function) >', this)
                console.log('this scope (vuejs) >', _this)
                console.log('this scope (vuejs) >', self)
                console.log('this scope (vuejs) >', that)
            })
        }
    }
}
</script>
Posted by: Guest on March-11-2021
0

scope of this keyword in vue js

<script>
export default {
    data:() => ({
        myData: 1
    }),
    mounted() {
        this.myMethod()
    },
    methods:{
        myMethod() {
            window.addEventListener('click', () => {
                console.log('this >', this.myData)
            })
        }
    }
}
</script>
Posted by: Guest on March-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language