5.2. 修改个人信息
简介
本小节中,我们将新建一个个人信息页面,并完成更新个人信息的功能。
更新个人信息
打开 src/store/index.js 文件,在 actions 里添加更新个人信息的事件 updateUser:
src/store/index.js
const actions = {
  login({ commit }, user) {
    if (user) commit('UPDATE_USER', user)
    commit('UPDATE_AUTH', true)
    router.push('/')
  },
  logout({ commit }) {
    commit('UPDATE_AUTH', false)
    router.push({ name: 'Home', params: { logout: true } })
  },
  // 更新个人信息
  updateUser({ state, commit }, user) {
    const stateUser = state.user
    if (stateUser && typeof stateUser === 'object') {
      user = { ...stateUser, ...user }
    }
    commit('UPDATE_USER', user)
  }
}更新个人信息的基本逻辑:
updateUser({ state, commit }, user) {
  // 获取仓库的个人信息
  const stateUser = state.user
  // 简单的数据类型判断... 
           V01 Vue.js 实战教程 - 基础篇
V01 Vue.js 实战教程 - 基础篇 
             
             关于 LearnKu
                关于 LearnKu
               
                     
                     
                     粤公网安备 44030502004330号
 粤公网安备 44030502004330号