Files
qingcheng-xiaochengxu/pages/personCenter/component/modifyNamePop/modifyNamePop.js
2025-08-15 00:36:04 +08:00

50 lines
879 B
JavaScript

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 });
}
}
});