$emit - daniel-qa/Vue GitHub Wiki
- 父子元件通訊(Props down / Events up)
emit
// 發出事件,通知父組件跳轉到分享學校課網頁面並選中該學校
this.$emit('approve-and-share', {
schoolCode: item.schoolCode,
schoolName: item.schoolName
});
事件接收:handleApproveAndShare
async handleApproveAndShare(schoolInfo) {
console.log('收到審核同意事件:', schoolInfo);
// 載入學校清單
await this.getAllSchoolList();
await this.$nextTick();
// 用 schoolCode 在 originSchoolList 中查找完整的學校物件
const school = this.originSchoolList.find(s => s.id === schoolInfo.schoolCode);
if (school) {
this.onSelectSchool(school); // ← 傳遞完整的學校物件
this.$Message.success(`已自動選中 ${schoolInfo.schoolName},請選擇要分享的課綱`);
}
}