先上效果:双击公司表行,下面客户员工表更新为改公司的员工
代码 index. vue:
<template>
<!-- 每个Col组件中,分别放置了Interval和Crontab组件 ,<Row :gutter="12",两快间距>:<Col :span="12">:定义了一个栅格列,span属性设置为12,表示该列占据全部可用的栅格空间-->
<div style="margin: 16px">
<Row>
<!-- <Row :gutter="12"> -->
<Col :span="24">
<CustomerData @handleRowDoubleClick="init" />
<!-- 自定义的组件 <CustomerData>,当这个组件触发 handleRowDoubleClick 事件时,调用 init 方法 -->
</Col>
</Row>
<Row style="margin-top: 12px">
<Col :span="24">
<CustomerStaff ref="CustomerStaffRef" />
<!-- 自定义的组件 <CustomerStaff>,通过 ref 属性设置了引用名称为 CustomerStaffRef -->
</Col>
</Row>
</div>
</template>
<script lang="ts" setup>
import { Row, Col } from 'ant-design-vue';
import { defineComponent, ref } from 'vue';
import CustomerData from '/@/views/basic_data/customer/customer_data/index.vue';
import CustomerStaff from '/@/views/basic_data/customer/customer_staff/index.vue';
const CustomerStaffRef = ref();
// 使用 ref 创建了一个名为 CustomerStaffRef 的引用,用来引用 <CustomerStaff> 组件的实例
function init(data: any) {
console.error(data);
console.error(CustomerStaffRef.value);
CustomerStaffRef.value.re_update(data);
}
// 定义了一个名为 init 的函数,接收一个参数 data,在控制台打印 data 和 CustomerStaffRef.value,然后调用 CustomerStaffRef.value.re_update(data) 方法
</script>
<style scoped></style>
在customer_staff文件里添加:
function re_update(data: any) {
searchInfo.company_ids = [data.id];
// 通过获取双击获取的ID, 作为GET请求参数,执行更改逻辑
reload();
}