R
R
Roman Sarvarov2020-06-07 02:17:04
JavaScript
Roman Sarvarov, 2020-06-07 02:17:04

Defining methods in the component. What is the difference?

Is there any difference between these three options?

Option 1

export default {
        methods: {
            test: () => {
                alert(1);
            }
        },
        mounted() {
            this.test();
        }
    }

Option 2

export default {
        methods: {
            test() {
                alert(1);
            }
        },
        mounted() {
            this.test();
        }
    }

Option 3

export default {
        methods: {
            test: function () {
                alert(1);
            }
        },
        mounted() {
            this.test();
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-06-07
@megakor

In the first case, the context will not be an instance of the bean, so if you want to call other methods or access properties inside the method, this option is not acceptable.
The second is a shorter notation of the third .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question