打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
玲子留言 | 贡献2025年5月28日 (三) 17:54的版本 (玲子移动页面用户:玲子/common.js用户:玲子/Common.js,不留重定向)

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
// Add a "Codex Widgets" portlet to the main menu
mw.util.addPortlet( 'p-codex', 'Codex Widgets', '#p-interaction' );
const dialogTrigger = mw.util.addPortletLink( 'p-codex', '#', 'Example Dialog Widget', 'p-codex-dialog' );

mw.loader.using( '@wikimedia/codex' ).then( function( require ) {
	const Vue = require( 'vue' );
	const Codex = require( '@wikimedia/codex' );
	const mountPoint = document.body.appendChild( document.createElement( 'div' ) );
	
	Vue.createMwApp( {
		data: function() {
			return {
				showDialog: false,
				count: 0,
				codexLink: 'https://doc.wikimedia.org/codex/latest/'
			};
		},
		template: `
			<cdx-dialog v-model:open="showDialog"
				title="Hello from Codex"
				close-button-label="Close"
				:default-action="defaultAction"
				@default="open = false"
			>
				<p>This Dialog component comes from Codex, the new design system for Wikimedia.</p>
				<p>To learn more about Codex, check out the documentation <a :href="codexLink" target="_blank">here.</a></p>
				<hr />
				<p>Click these buttons to update the reactive count value:</p>
				<p>Count: {{ count }}</p>
				<p>
					<cdx-button action="destructive" @click="decrement">Decrease</cdx-button>
					<cdx-button action="progressive" @click="increment">Increase</cdx-button>
				</p>
			</cdx-dialog>
		`,
		methods: {
			openDialog () {
				this.showDialog = true;
			},
			increment() {
				this.count++;
			},
			decrement() {
				this.count--;
			}
		},
		mounted() {
			dialogTrigger.addEventListener( 'click', this.openDialog );
		},
		unMounted() {
			dialogTrigger.removeEventListener( this.openDialog );
		}
	} )
	.component( 'cdx-button', Codex.CdxButton )
	.component( 'cdx-dialog', Codex.CdxDialog )
	.mount( mountPoint );
} );