Using custom events in a component that is registered programmatically [VUE]

此生再无相见时 提交于 2019-12-11 15:49:54

问题


i am appending a child component in Vue programmatically as seen below:

var ComponentClass = Vue.extend(FormulaGeneratorConstant) //create instance from FormulaGeneratorConstant component

this.constants.push('variable1');

var constant = new ComponentClass({
    propsData: {
        value: this.constants[this.constants.length - 1]
    }
});

constant.$mount();

this.$refs.droppableContainer.$el.appendChild(constant.$el)

but right now i can only pass props in this code.

i would like to know how to implement v-model and handle custom events as well if that is possible.


回答1:


Found the solution here.

i just passed a created function inside the new Component constructor:

var constant = new ComponentClass({
    propsData: {
        value: this.constants[this.constants.length - 1]
    },
    created(){
        this.$on(['change'], e => { console.log(e); })
    }
});



来源:https://stackoverflow.com/questions/59004422/using-custom-events-in-a-component-that-is-registered-programmatically-vue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!