Skip to content

Commit 2b44f1d

Browse files
committed
fix:个人中心修改信息后,左侧没变化
1 parent 02d284b commit 2b44f1d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/views/Profile/Index.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<span>{{ t('profile.user.title') }}</span>
88
</div>
99
</template>
10-
<ProfileUser />
10+
<ProfileUser ref="profileUserRef" />
1111
</el-card>
1212
<el-card class="user ml-3 w-2/3" shadow="hover">
1313
<div>
1414
<el-tabs v-model="activeName" class="profile-tabs" style="height: 400px" tab-position="top">
1515
<el-tab-pane :label="t('profile.info.basicInfo')" name="basicInfo">
16-
<BasicInfo />
16+
<BasicInfo @success="handleBasicInfoSuccess" />
1717
</el-tab-pane>
1818
<el-tab-pane :label="t('profile.info.resetPwd')" name="resetPwd">
1919
<ResetPwd />
@@ -32,6 +32,12 @@ import { BasicInfo, ProfileUser, ResetPwd, UserSocial } from './components'
3232
const { t } = useI18n()
3333
defineOptions({ name: 'Profile' })
3434
const activeName = ref('basicInfo')
35+
const profileUserRef = ref()
36+
37+
// 处理基本信息更新成功
38+
const handleBasicInfoSuccess = async () => {
39+
await profileUserRef.value?.refresh()
40+
}
3541
</script>
3642
<style scoped>
3743
.user {

src/views/Profile/components/BasicInfo.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ defineOptions({ name: 'BasicInfo' })
2828
const { t } = useI18n()
2929
const message = useMessage() // 消息弹窗
3030
const userStore = useUserStore()
31+
32+
// 定义事件
33+
const emit = defineEmits<{
34+
(e: 'success'): void
35+
}>()
36+
3137
// 表单校验
3238
const rules = reactive<FormRules>({
3339
nickname: [{ required: true, message: t('profile.rules.nickname'), trigger: 'blur' }],
@@ -82,6 +88,8 @@ const submit = () => {
8288
message.success(t('common.updateSuccess'))
8389
const profile = await init()
8490
userStore.setUserNicknameAction(profile.nickname)
91+
// 发送成功事件
92+
emit('success')
8593
}
8694
})
8795
}

src/views/Profile/components/ProfileUser.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ const getUserInfo = async () => {
6060
const users = await getUserProfile()
6161
userInfo.value = users
6262
}
63+
64+
// 暴露刷新方法
65+
defineExpose({
66+
refresh: getUserInfo
67+
})
68+
6369
onMounted(async () => {
6470
await getUserInfo()
6571
})

0 commit comments

Comments
 (0)