父组件 import { students, studentDel } from "@/api/api.js"; // eslint-disable-next-line no-unused-vars import { ref, reactive, toRefs, onMounted, useContext, computed, getCurrentInstance } from 'vue' import child_student from './child_student.vue' export default { components: { // eslint-disable-next-line vue/no-unused-components child_student }, setup() { const { proxy } = getCurrentInstance() console.log(proxy, '53****') const child_student =ref(null) const dataList = reactive({ tableData: [], currentPage: 1, //当前页数 pageSize: 10, // 每页显示条数 total: 0, // 总条数 formInline: { name: "", }, count:0 }) const compData = computed(() => { return dataList.tableData.slice( (dataList.currentPage - 1) * dataList.pageSize, dataList.currentPage * dataList.pageSize ); }) const dataMethod = { getObject(){ dataList.count+=1; console.log(dataList.count,'81//////') }, getList() { dataMethod.father() }, father() { alert('1233333333') }, find() { child_student.value.expose() console.log(dataList.formInline); dataMethod.getData(dataList.formInline) }, reset() { console.log(dataList.formInline); // @ts-ignore dataList.formInline = {} dataMethod.getData(dataList.formInline) }, handleSizeChange(val) { dataList.pageSize = val; dataList.currentPage = 1; }, handleCurrentChange(val) { dataList.currentPage = val; }, getData(params) { students(params).then((res) => { if (res.data.status === 200) { dataList.tableData = res.data.data; dataList.total = res.data.total; console.log(res); dataList.tableData.forEach((item) => { // 尽量不要修改原数据 item.sex === 1 ? (item.sex_text = "男") : (item.sex_text = "女"); item.state === "1" ? (item.state_text = "已入学") : item.state === "2" ? (item.state_text = "未入学") : (item.state_text = "休学中"); }); } }); }, del(row) { console.log(row); studentDel(row.id).then((res) => { console.log(res); if (res.data.status === 200) { proxy.$message({ message: "删除数据成功", type: "success" }); dataMethod.getData(); } }); }, } onMounted(() => { dataMethod.getData(); child_student.value.expose() console.log(child_student.value.count, '138****/*/*') }) return { ...toRefs(dataList), ...dataMethod, compData, child_student } } } 子组件
子传父数字
子传父对象