Answer the question
In order to leave comments, you need to log in
How to inject a component into a vue js component?
Vue.component('ComponentName', ComponentDefinition);
...
props: {
compName: { type: String, default: '' }
propsData: { type: Object, default: {} }
}
<component :is="compName" v-bind=propsData>
<!-- вот тут compName строка с именем ранее зар-ного компонента -->
import comp from '@/path/comp.vue';
...
props: {
comp: { type: Object, default: {} }
propsData: { type: Object, default: {} }
}
<component :is="comp" v-bind=propsData>
<!-- вот тут comp уже передан как объект, не строка с именем ранее зар-ного компонента -->
Answer the question
In order to leave comments, you need to log in
If you use a modular assembly system, then you can do this:
<template>
<component :is="comp" v-bind=propsData>
</template>
<script>
import comp from '@/path/comp.vue';
export default {
props: ['propsData'],
data() {
return {
comp
}
}
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question