【发布时间】:2019-06-17 16:17:08
【问题描述】:
我有一个带有如下配置对象的确认弹出 Vue 组件:
{
title: null,
message: null,
onConfirm: null,
onDismiss: null,
modal_class: null,
icon: null,
confirmBtnText: null,
confirmBtnColor: null,
component: null
}
在模板中,我想在这里呈现一个“动态”组件:
<component class="component-container" :is="component"></component>
我正在初始化传入的组件,如下所示:
import {CarrierSaferInfo} from './path/to/single-file-component.vue'
let SaferInfo = Vue.extend(CarrierSaferInfo)
let SaferComp = new SaferInfo({
propsData: {
carrier,
dom_class: 'text-white',
}
})
openConfirmDialog({
//...other props
component: SaferComp
})
但我得到了错误:
Failed to mount component: template or render function not defined.
编辑:
我现在尝试使用组件的实际 $options 对象,如下所示:
<component class="component-container" :is="component.$options"></component>
在组件定义中,prop carrier 是必需的。事件虽然在$options 对象中显示carrier 中的propsData 道具是一个对象,但它仍然在说:
Missing required prop: carrier
所以,取得了进展,但现在 propsData 由于某种原因没有填充到渲染函数中。
【问题讨论】:
-
我不认为你可以将 'is' 属性绑定到 div 元素...你试过这个:
-
@SirDad 我刚刚尝试过,它给出了同样的错误
-
我不熟悉你初始化它的方式,但
:is需要string所以:is='SaferInfo' -
@SatyamPathak 我以这种方式初始化组件的原因是因为每次初始化组件时都需要更改道具。从文档中,
:is属性将采用名称(您的建议)或组件选项对象(对于我的示例来说是必需的)
标签: vue.js