vue3 绑定form弹窗的方式

一、v-model="visibleProject"对应 :visible="model" const model = defineModel({ type: Boolean });

可以 在组件里对子组件visible 绑定的model单独监听

父组件
  <projectAllocation v-model="visibleProject"></projectAllocation>
 import projectAllocation from "./componts/project-allocation.vue";
 const visibleProject = ref(false);

 子组件弹窗
 <template>
    <!-- <div>项目分配</div> -->
    <a-drawer :visible="model" width="800px" title="详情" ok-text="关闭" :hideCancel="true"></a-drawer>
</template>

<script setup>
import { reactive, ref, watch } from "vue";

const model = defineModel({ type: Boolean });
watch(model, () => {
    if (model.value) {
        console.log(model.value, "dddddddddddd");
    }
});
</script>

<style lang="scss" scoped></style>

二、v-model:visible="visibleProject" 对应 v-bind="$attrs"

v-bind="$attrs" 的作用是将父组件传递给当前组件的所有非 prop 特性动态地绑定到 <a-drawer> 组件上。

这种用法通常在开发基础组件时非常有用,因为它允许你在不清楚父组件会传递哪些特性的情况下,将所有的非 prop 特性都传递给子组件。这样可以实现对特性的透传,使得父组件可以自定义子组件的外观和行为。

举个例子,如果父组件包含类似 classstyle 等特性,通过使用v-bind="$attrs",这些特性都会被动态地绑定到 <a-drawer> 组件上,从而实现了对外部特性的透传。

 父组件
 <projectAllocation v-model:visible="visibleProject"></projectAllocation>
 import projectAllocation from "./componts/project-allocation.vue";

 子组件弹窗
   <template>
    <!-- <div>项目分配</div> -->
    <a-drawer v-bind="$attrs" width="800px" title="详情" ok-text="关闭" :hideCancel="true"></a-drawer>
</template>

<script setup>
import { reactive, ref, watch } from "vue";
</script>

<style lang="scss" scoped></style>

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值