1

How can I add an internal and external parameter to an event listener at the same time?

<myComp @do="wrapDo($event, 5)"></myComp>
function wrapDo(objectFromComp, myIntegerParameter){
    // objectFromComp is okey :)
    // myIntegerParameter is undefined :(
}

In myComp.vue:

this.$emit('do', { text: "return object from component"} );

I tried this but get undefined:

@do="x => wrapDo(x, 5)"

1 Answer 1

2

It should work fine, just make sure you have that function in methods:

Vue.component('mycomp', {
  template: `
  <div>
    <button @click="$emit('do', { text: 'return object from component'})">Emit</button>
  </div>
  `
})

new Vue({
  el: "#app",
  methods: {
    wrapDo(objectFromComp, myIntegerParameter) {
      console.log(objectFromComp, myIntegerParameter);
    }
  },
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <mycomp @do="wrapDo($event, 5)"></mycomp>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

thx @dan dont know that happing but all work after restart VSCode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.