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>

相关推荐

  1. vue3 form方式

    2024-03-29 15:52:05       14 阅读
  2. Vue中Class和style方式

    2024-03-29 15:52:05       20 阅读
  3. VUE3+X6流程图实现数据双向方案

    2024-03-29 15:52:05       20 阅读
  4. Vue3封装可拖拽

    2024-03-29 15:52:05       35 阅读
  5. vue动态class几种方法

    2024-03-29 15:52:05       13 阅读
  6. vue3组件数据双向

    2024-03-29 15:52:05       29 阅读
  7. vue3-类与样式

    2024-03-29 15:52:05       27 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-29 15:52:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-29 15:52:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-29 15:52:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-29 15:52:05       18 阅读

热门阅读

  1. angular 组件传值交互

    2024-03-29 15:52:05       17 阅读
  2. Python进行DevOps实践

    2024-03-29 15:52:05       14 阅读
  3. Calendar日历类

    2024-03-29 15:52:05       17 阅读
  4. Python教程:一文掌握Python多线程(很详细)

    2024-03-29 15:52:05       15 阅读
  5. 离散数对问题

    2024-03-29 15:52:05       16 阅读
  6. CentOS 7 安装python 3.7 需要必要的依赖。

    2024-03-29 15:52:05       15 阅读
  7. 关于rockylinux9的网络配置

    2024-03-29 15:52:05       13 阅读
  8. 《享元模式(极简c++)》

    2024-03-29 15:52:05       16 阅读