元件盒 - daniel-qa/Vue GitHub Wiki

元件盒

  • 跳出複選的對話方塊
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Vue 示例</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="./app.js" defer></script>
</head>
<body>
    <div id="app">
        <div>
            <button @click="showDialog = true">顯示對話框</button>

            <div v-if="showDialog" class="dialog-overlay">
                <div class="dialog">
                    <h3>這是一個對話框</h3>
                    <p>你確定要執行此操作嗎?</p>
                    <div class="dialog-buttons">
                        <button @click="confirm">確定</button>
                        <button @click="cancel">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        const { createApp } = Vue;

        createApp({
            data() {
                return {
                    showDialog: false,
                };
            },
            methods: {
                confirm() {
                    console.log('確認操作');
                    this.showDialog = false;
                },
                cancel() {
                    console.log('取消操作');
                    this.showDialog = false;
                },
            },
        }).mount('#app');
    </script>

    <style>
        .dialog-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .dialog {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }

        .dialog-buttons {
            display: flex;
            justify-content: space-between;
        }
    </style>
</body>
</html>
⚠️ **GitHub.com Fallback** ⚠️