vue.js中如何给元素动态添加属性?

这里写自定义目录标题


封装组件的时候属性为动时怎么绑定属性

 {
    property: 'positionId',
    title: '版位',
    type: 'select',
    required: false,
    multiple: false,
    options: [],
    placeholder: '请选择',
  },
  {
    property: 'type',
    title: '广告类型',
    type: 'slot',
    componment: radioTab,
    ref: 'type',
    attrs: { videoContent: '', imageContent: '', stringContent: '' },//动态的属性
  },
  <template v-else-if="item.type === 'slot'">
          <component
            v-if="formVisible"
            :is="item.componment"
            v-bind="item.attrs"  //渲染
            :key="item.property"
            :ref="item.property"
          />
        </template>

由于已经在一个对象中有属性,可以直接将它传递给v-bind;如下例子

<a v-bind="item.attrs">{{ item.label }}</a>

这将导致attrs对象中的键作为属性和attrs中的值作为对应值。

你可能感兴趣的:(vue.js,前端)