Component({ properties: { show: { type: Boolean, value: false }, nickname: { type: String, value: '' } }, data: { inputVal: '' }, methods: { onInput(e) { this.setData({ inputVal: e.detail.value }); }, onCancel() { this.triggerEvent('cancel'); }, onConfirm() { const newName = this.data.inputVal.trim(); if (!newName) { wx.showToast({ title: '昵称不能为空', icon: 'none' }); return; } if (newName.length > 20) { wx.showToast({ title: '昵称最长不超过20个字符', icon: 'none' }) return ; } this.triggerEvent('confirm', { nickname: newName }); } }, observers: { nickname(val) { this.setData({ inputVal: val }); } } });