关于$attr的文字

我定义了一个自定义组件,代码如下
<template>
<el-alert v-bind="$attrs">
</el-alert>
</template>
然后父级通过这个方法调用时,props的值都没生效请问是为什么
deleteFun(item){

    const h = this.$createElement;
    this.$msgbox({
      title:'确认删除',
      customClass:"confirm-box",
      closeOnClickModal:false,
      message: h('div', null, [
        h('p', null, '是否彻底删除此视频源,删除后不可恢复!'),
        h(BaseAlert, {
          props: {
            title:"警告提示的文案",
            closable:false,
            type:"warning"
          }
        })
      ]),
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      showCancelButton: true,
    }).then((action) => {
      if (action === 'confirm') {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }
    }).catch(() => {

    });
  }
阅读 1.1k
1 个回答

通过props传入的,需使用$props访问。

官网是这么说的:
vm.$attrs:包含了父作用域中不作为 prop 被识别 (且获取) 的 attribute 绑定 (class 和 style 除外)
vm.$props:当前组件接收到的 props 对象。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题