File tree Expand file tree Collapse file tree 3 files changed +43
-24
lines changed Expand file tree Collapse file tree 3 files changed +43
-24
lines changed Original file line number Diff line number Diff line change 11<template >
2- <div v-if =" isVisible" class =" fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center" >
3- <div class =" bg-white rounded-lg p-6 w-1/3" >
4- <button @click =" closeModal" class =" text-red-500" >關閉</button >
5- <p class =" mt-4" >這是彈出式 Modal 的內容</p >
2+ <div class =" fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center" >
3+ <div class =" bg-white rounded-lg p-6 w-1/3 relative" >
4+ <button @click =" $emit('closeModal')" class =" text-red-500 absolute top-2 right-3 font-bold p-2" >x</button >
5+ <form @submit.prevent =" handleSubmit" >
6+ <div class =" mb-4" >
7+ <label for =" name" class =" block text-gray-700" >姓名</label >
8+ <input type =" text" id =" name" v-model =" name" class =" border rounded w-full py-2 px-3" required />
9+ </div >
10+ <div class =" mb-4" >
11+ <label for =" email" class =" block text-gray-700" >電子郵件</label >
12+ <input type =" email" id =" email" v-model =" email" class =" border rounded w-full py-2 px-3" required />
13+ </div >
14+ <button type =" submit" class =" bg-blue-500 text-white rounded py-2 px-4 absolute bottom-2 right-4" >送出</button >
15+ </form >
616 </div >
717 </div >
818</template >
919
10- <script setup>
11- import { ref } from ' vue'
12-
13- const isVisible = ref (false )
14-
15- const openModal = () => {
16- isVisible .value = true
17- }
18-
19- const closeModal = () => {
20- isVisible .value = false
21- }
22-
23-
20+ <script >
21+ export default {
22+ data () {
23+ return {
24+ name: ' ' ,
25+ email: ' '
26+ };
27+ },
28+ methods: {
29+ handleSubmit () {
30+ // 處理表單提交
31+ console .log (' 姓名:' , this .name );
32+ console .log (' 電子郵件:' , this .email );
33+ this .$emit (' closeModal' ); // 提交後關閉 Modal
34+ }
35+ }
36+ };
2437 </script >
Original file line number Diff line number Diff line change 33 <el-table v-if =" tableHeader.length !== 0" :data =" tableData" class =" bg-white rounded-lg shadow text-lg" >
44 <el-table-column v-for =" (col, index) in tableHeader" :prop =" col" :label =" col" :key =" index" />
55 <el-table-column prop =" edit" label =" edit" >
6- <el-button @click =" $emit('getFormData', name)" type =" primary" class =" bg-gray-500 hover:bg-gray-600 border-gray-500 hover:border-gray-600" >
6+ <el-button @click =" $emit('getFormData', name); $emit('openModal') " type =" primary" class =" bg-gray-500 hover:bg-gray-600 border-gray-500 hover:border-gray-600" >
77 <el-icon ><Edit /></el-icon >
88 </el-button >
99 </el-table-column >
2424 default : () => []
2525 }
2626 })
27- defineEmits ([' getFormData' ])
27+ defineEmits ([' getFormData' , ' openModal ' ])
2828 </script >
Original file line number Diff line number Diff line change 88 <el-button type =" primary" class =" bg-gray-500 hover:bg-gray-600 border-gray-500 hover:border-gray-600" >新增</el-button >
99 </el-header >
1010
11- <Table :tableData =" tableData" :tableHeader =" tableHeader" @getFormData =" getFormData" />
11+ <Table :tableData =" tableData" :tableHeader =" tableHeader" @getFormData =" getFormData" @openModal = " openModal " />
1212
1313 </el-container >
14- <Modal />
14+ <Modal class = " z-50 " v-if = " isVisible " @closeModal = " closeModal " />
1515 </el-container >
1616 </main >
1717</template >
2929
3030 const router = useRouter ()
3131
32-
33-
3432 const sidebarOpen = ref (true )
3533 const toggleSidebar = async () => {
3634 sidebarOpen .value = ! sidebarOpen .value
6563 }
6664 }
6765
66+ const isVisible = ref (false )
67+ const openModal = () => {
68+ isVisible .value = true
69+ }
70+ const closeModal = () => {
71+ isVisible .value = false
72+ }
73+
6874 const getFormData = async () => {
6975 console .log (' hello' )
7076 }
You can’t perform that action at this time.
0 commit comments