父子表 --vue 点击按钮弹出弹窗

文章介绍了在Vue.js项目中如何通过点击按钮实现父组件向子组件传递事件,展示了一个包含按钮效果的父表和弹出使用记录、维修等子表的示例,以及如何在子表中进行表单验证和操作。
摘要由CSDN通过智能技术生成

1.效果图

按钮效果 --父表

点击按钮之后的 -- 子表

2.代码部分

1.父表

<template>
  <basic-containers>
    <el-row :gutter="20">
      <el-col :span="6">
        <el-button icon="el-icon-tickets" @click="onOpenUseRecord" >使用记录</el-button>
      </el-col>
      <el-col :span="6">
        <el-button icon="el-icon-tickets" @click="onOpenmaintainRecord" >维修记录</el-button>
      </el-col>
      <el-col :span="6">
        <el-button icon="el-icon-tickets" @click="onOpenscrapRecord" >报废记录</el-button>
      </el-col>
      <el-col :span="6">
        <el-button icon="el-icon-tickets" @click="onOpenfaultRecord" >故障记录</el-button>
      </el-col>

    </el-row>
    <use-record ref="useRecordRefs"></use-record>
    <scrap-record ref="scrapRecordRefs"></scrap-record>
    <fault-record ref="faultRecordRefs"></fault-record>
    <maintain-record ref="maintainRecordRefs"></maintain-record>
  </basic-containers>
</template>
<script>
import useRecord from "@/views/test/dialog/useRecord";
import scrapRecord from "@/views/test/dialog/scrapRecord";
import maintainRecord from "@/views/test/dialog/maintainRecord";
import faultRecord from "@/views/test/dialog/faultRecord";
export default {
  name:'DemoIndex',
  components:{
    useRecord,
    scrapRecord,
    maintainRecord,
    faultRecord,
  },
  data() {
    return {};
  },
  methods:{
    onOpenUseRecord(){
      this.$refs.useRecordRefs.openDialog('add');
    },
    onOpenscrapRecord(){
      this.$refs.scrapRecordRefs.openDialog('add');
    },
    onOpenmaintainRecord(){
      this.$refs.maintainRecordRefs.openDialog();
    },
    onOpenfaultRecord(){
      this.$refs.faultRecordRefs.openDialog('add');
    }
  }
};
</script>

2.子表

<template>
  <basic-dialog
      :visible.sync="dialog.showDialog"
      :title="dialog.title"
      width="40%"
      :submit-txt="dialog.submitTxt"
      :loading="dialog.loading"
      append-to-body
      @cancel="cancleDialog"
      @submit="submitDialog"
  >
    <!-- 内容   -->
    <avue-form v-model="form" :option="option"></avue-form>
  </basic-dialog>
</template>
<script>
export default {
  name: "useRecord",
  data() {
    return {
      dialog:{
        showDialog:false,
        title:"使用记录",
        submitTxt:"提交",
        loading:false,
      },
      form:{},
      option:{
        emptyBtn:false,
        submitBtn:false,
        column:[
           {
          label: "型号",
          prop: "modelName",

  },
    {
          label: "产品名称",
          prop: "productName",

    },
    {
      label: "产品编号",
          prop: "productCode",
      rules: [{ required: true, message: "产品编号不能为空" }],

    },
    {
      label: "规程编号",
          prop: "specificationCode",
    },
    {
      label: "规程名称",
          prop: "specificationName",
    },
    {
      label: "规程版本",
          prop: "specificationRev",
    },  {
      label: "工步号",
          prop: "processCode",
    },  {
      label: "工步名称",
          prop: "processName",
    },  {
      label: "使用人",
          prop: "borrowUserName",
    },  {
      label: "使用时间",
          prop: "borrowDateTime",
            type: "date",

          }
        ]
      }
    };
  },
  methods:{
    //打开弹窗
    openDialog(event){
      console.log(event);
      this.dialog.showDialog   = true;
    },
    //关闭弹窗
    cancleDialog(){
      this.dialog.showDialog = false;
    },
    submitDialog(){
      //自定义逻辑
    }
  }
};

</script>

<style scoped>

</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 vant 组件库中的 van-popover 组件来实现这个功能。首先,你需要在你的 Vue 项目中安装 vant: ```bash npm i vant -S ``` 然后,在你的组件中引入 van-popover 组件: ```javascript <template> <div> <van-button type="primary" @click="showPopover($event)">显示 Popover</van-button> <van-popover v-model="show" :actions="actions" :placement="placement" :offset="offset" /> </div> </template> <script> import { ref } from 'vue'; import { Button, Popover } from 'vant'; export default { components: { [Button.name]: Button, [Popover.name]: Popover, }, setup() { const show = ref(false); const actions = [ { name: '选项一', icon: 'success' }, { name: '选项二', icon: 'plus' }, { name: '选项三', icon: 'search' }, { name: '选项四', icon: 'like-o' }, { name: '选项五', icon: 'edit' }, ]; const placement = ref('bottom'); const offset = ref(0); const showPopover = (event) => { show.value = true; offset.value = [event.target.offsetWidth / 2, 10]; }; return { show, actions, placement, offset, showPopover, }; }, }; </script> ``` 在上面的代码中,我们先引入了 vant 的 Button 和 Popover 组件,然后在 setup 函数中定义了一些变量和方法,包括 show、actions、placement、offset 和 showPopover。其中,show 示 Popover 是否显示,actions 示 Popover 中的选项,placement 示 Popover 的位置,offset 示 Popover 的偏移量,showPopover 是点击按钮时触发的方法。 在模板中,我们使用了 van-button 组件来显示一个按钮,当该按钮被点击时,会触发 showPopover 方法,显示 Popover 组件。Popover 组件的 v-model 绑定到 show 变量,actions、placement 和 offset 属性分别绑定到 actions、placement 和 offset 变量。 最后,我们在 showPopover 方法中计算了 Popover 的偏移量,使其在按钮正下方显示。你可以根据实际需要修改 placement 和 offset 变量来调整 Popover 的位置和偏移量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值