赞
踩
vue的内置组件component,可以将一个“元组件”渲染为一个动态组件,根据is
属性的值,来控制渲染为什么组件
<!-- 动态组件由 vue实例的 `componentId` property 控制 -->
<component :is="componentId"></component>
<!-- 也能够渲染注册过的组件或 prop 传入的组件 -->
<component :is="$options.components.child"></component>
<component :is="demoComponent" ></component>
import demoComponent from './demoComponent '
大部分需要使用for循环去渲染不同组件的场景都适用
例如 渲染工具栏组件
<component
v-for="(widgetOption, index) in WidgetOptions"
:key="index"
:is="widgetOption.name"
:options="widgetOption.options"
class="public-toolWidget-class"
></component>
>
import * as DrawControl from "./DrawControl"
import * as QueryControl from "./QueryControl"
import * as LabelControl from "./LabelControl"
WidgetOptions数组
WidgetOptions = [{ name: "DrawControl", options: { default: 999 }},
{ name: "QueryControl", options: { default: 999 }},
{ name: "LabelControl", options: { default: 999 }}]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。