F
F
furrya_black2017-08-09 19:10:20
Vue.js
furrya_black, 2017-08-09 19:10:20

Passing props to new Component(el, propsData), why doesn't the click handler from propsData fire?

I create a button component like this

createElButton(options = {}, el) {
    let ButtonComponent = Vue.extend(ElButton);
    let buttonInstance = new ButtonComponent({
      el: el,
      propsData: options
    });
    console.log(buttonInstance);
    return buttonInstance;
  }

In propsData, respectively, props of the component.
The button is rendered, the passed parameters all end up in the new component instance (String, Object, Array, etc.)
The only thing that doesn't work is the button click callback.
<a class="button" v-on:click="onClick"></a> // что так
<a class="button" v-on:click="clickHandler"></a> // что этак

// не срабатывает

props: {
   onClick: { type: Function, default() {} }
}

methods: {
    clickHandler() {
        console.log('clickHandler called');
        this.onClick();
    }
}

// clickHandler called в конслои не вываливается

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2017-08-10
@furrya_black

And why do it like this, if you can do $emit in @click and already write v-on:click in the parent, as everyone else does?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question