11. Springboot3+vue3实现个人中心、修改密码 – 朝汐の小站
11. Springboot3+vue3实现个人中心、修改密码
本文最后更新于 283 天前,如有错误请邮件至 zhiligyi222na@gmail.com

前端常见报错

username没有被定义

main部分的数据传递

Person.vue

const emit = defineEmits(['updateUser'])

const update = () => {
  let url
  if (data.user.role === 'ADMIN'){
    url = '/admin/update'
  }
  if (data.user.role === 'USER'){
    url = '/user/update'
  }
  request.put(url, data.user).then(res => {
    if (res && res.code === '200'){
      ElMessage.success('修改成功')
      localStorage.setItem('code_user', JSON.stringify(res.data))
      emit('updateUser', res.data) // 传递更新后的用户数据
    } else if (res) {
      ElMessage.error(res.msg)
    }
  }).catch(error => {
    console.error('请求失败:', error)
  })
}

Manager.vue

<RouterView @updateUser="updateUser"/>

const updateUser = () => {
  data.user = JSON.parse(localStorage.getItem("code_user") || "{}")
}

修改密码

const updatePassword = () => {
    formRef.value.validate(valid => {
      if (valid) {
        request.post('/updatePassword', data.user).then(res => {
          if (res.code === '200') {
            ElMessage.success('修改成功');
            setInterval(() => {
              localStorage.removeItem('code_user')
              location.href = '/login';
            }, 500)
          } else {
            ElMessage.error(res.msg);
          }
        })
      }
    })
  }
文末附加内容
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇