Y
Y
Yaroslav Ivanov2020-02-13 15:22:39
JavaScript
Yaroslav Ivanov, 2020-02-13 15:22:39

Is it possible to nest a method in an object in vue?

Now I use a method call like this I want to call a method like this The current structure of methods:
<button @click="packet().send()">Send</button>

<button @click="packet.send()">Send</button>

new Vue({
    methods: {
        packet() {
            return {
                send() {},
                recieve() {}
            }
        }
    }
})


What other way is there to nest a method?
You cannot nest a method in an object in the methods section. Vue complains about this
[Vue warn]: Method "packet" has type "object" in the component definition. Did you reference the function correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-02-13
@space2pacman

Make packet a property, not a method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question