打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
无编辑摘要
无编辑摘要
第1行: 第1行:
// Get the page content
(function() {
const content = document.getElementById( 'mw-content-text' );
    'use strict';
if ( !content ) {
return;
}
const container = document.createElement( 'div' );
content.insertBefore( container, content.firstChild );


mw.loader.using( '@wikimedia/codex' ).then( function( require ) {
    // 等待页面加载完成
const Vue = require( 'vue' );
    mw.loader.using(['vue', 'codex']).then(function() {
const Codex = require( '@wikimedia/codex' );
        // 创建 Vue 应用
        const app = Vue.createApp({
Vue.createMwApp( {
            data() {
data: function() {
                return {
return {
                    showDialog: false
showDialog: false,
                }
count: 0,
            },
codexLink: 'https://doc.wikimedia.org/codex/latest/'
            methods: {
};
                openDialog() {
},
                    this.showDialog = true;
template: `
                },
<cdx-dialog v-model:open="showDialog"
                closeDialog() {
title="Hello from Codex"
                    this.showDialog = false;
close-button-label="Close"
                }
:default-action="defaultAction"
            },
@default="open = false"
            template: `
>
                <div>
<p>This Dialog component comes from Codex, the new design system for Wikimedia.</p>
                    <cdx-button
<p>To learn more about Codex, check out the documentation <a :href="codexLink" target="_blank">here.</a></p>
                        weight="primary"
<hr />
                        @click="openDialog"
<p>Click these buttons to update the reactive count value:</p>
                    >
<p>Count: {{ count }}</p>
                        打开对话框
<p>
                    </cdx-button>
<cdx-button action="destructive" @click="decrement">Decrease</cdx-button>
 
<cdx-button action="progressive" @click="increment">Increase</cdx-button>
                    <cdx-dialog
</p>
                        v-model:open="showDialog"
</cdx-dialog>
                        title="提示"
`,
                        @close="closeDialog"
methods: {
                    >
openDialog () {
                        <p>这是一个使用 Codex 和 Vue 实现的对话框示例。</p>
this.showDialog = true;
                        <template #footer>
},
                            <cdx-button
increment() {
                                weight="primary"
this.count++;
                                @click="closeDialog"
},
                            >
decrement() {
                                确定
this.count--;
                            </cdx-button>
}
                        </template>
},
                    </cdx-dialog>
mounted() {
                </div>
dialogTrigger.addEventListener( 'click', this.openDialog );
            `
},
        });
unMounted() {
 
dialogTrigger.removeEventListener( this.openDialog );
        // 创建容器元素
}
        const container = document.createElement('div');
} )
        container.id = 'codex-demo';
.component( 'cdx-button', Codex.CdxButton )
        document.body.appendChild(container);
.component( 'cdx-dialog', Codex.CdxDialog )
 
.mount( container );
        // 挂载 Vue 应用
} );
        app.mount('#codex-demo');
    });
})();

2025年5月28日 (三) 20:32的版本

(function() {
    'use strict';

    // 等待页面加载完成
    mw.loader.using(['vue', 'codex']).then(function() {
        // 创建 Vue 应用
        const app = Vue.createApp({
            data() {
                return {
                    showDialog: false
                }
            },
            methods: {
                openDialog() {
                    this.showDialog = true;
                },
                closeDialog() {
                    this.showDialog = false;
                }
            },
            template: `
                <div>
                    <cdx-button
                        weight="primary"
                        @click="openDialog"
                    >
                        打开对话框
                    </cdx-button>

                    <cdx-dialog
                        v-model:open="showDialog"
                        title="提示"
                        @close="closeDialog"
                    >
                        <p>这是一个使用 Codex 和 Vue 实现的对话框示例。</p>
                        <template #footer>
                            <cdx-button
                                weight="primary"
                                @click="closeDialog"
                            >
                                确定
                            </cdx-button>
                        </template>
                    </cdx-dialog>
                </div>
            `
        });

        // 创建容器元素
        const container = document.createElement('div');
        container.id = 'codex-demo';
        document.body.appendChild(container);

        // 挂载 Vue 应用
        app.mount('#codex-demo');
    });
})();