手機(jī)移動網(wǎng)絡(luò)限制網(wǎng)站武漢電腦培訓(xùn)學(xué)校有哪些
當(dāng)父組件調(diào)用子組件的script setup
中的方法時,必須顯式導(dǎo)出該方法。因?yàn)?script setup
中定義的變量和方法默認(rèn)是局部的,只有顯式導(dǎo)出后,父組件才能訪問這些方法。
//父組件-Parent
<template><el-button type="primary" @click="addOrUpdateHandle()">{{ $i18("add") }}</el-button><!-- 彈窗, 新增 / 修改 --><add-or-update ref="addOrUpdateRef"></add-or-update>
</template>
<script setup>
import { unref } from "vue";
const addOrUpdateHandle = (row) => {const instance = unref(addOrUpdateRef);if (instance && typeof instance.init === "function") {instance.init(row);}
};
</script>
//子組件-Child
<template><el-dialogv-model="visible"></el-dialog>
</template>
<script setup>
import { reactive } from "vue";
const state = reactive({visible: false,
});
const init = () => {state.visible = true;
};
// 使用 defineExpose 導(dǎo)出 init 方法
defineExpose({init,
});
</script>