1.改造登入vue/src/views/LoginView.vue,登陸後儲存user資訊到sessionStorage,進入到login頁面移除sessionStorage裡的user
2.改造vue/src/components/Header.vue,從sessionStorage中獲取user,每個人登陸後根據個人資訊顯示名稱
3.增加vue/src/views/Person.vue,點選個人資訊,可帶入個人資訊後儲存
<template>
<div>
<el-card style="width: 150%; margin: 10px">
<el-form ref="form" :model="form" label-width="60px">
<el-form-item label="使用者名稱">
<el-input v-model="form.username" disabled></el-input>
</el-form-item>
<el-form-item label="暱稱">
<el-input v-model="form.nickName"></el-input>
</el-form-item>
<el-form-item label="年齡">
<el-input v-model="form.age"></el-input>
</el-form-item>
<el-form-item label="性別">
<el-input v-model="form.sex"></el-input>
</el-form-item>
<el-form-item label="地址">
<el-input v-model="form.address" type="textarea"></el-input>
</el-form-item>
<el-form-item label="密碼">
<el-input v-model="form.password"></el-input>
</el-form-item>
</el-form>
<div style="text-align: center">
<el-button type="primary" @click="update">更新儲存</el-button>
</div>
</el-card>
</div>
</template>
<script>
import request from "@/utils/request";
export default {
name: "Person",
data() {
return {
form: {}
}
},
created() {
let str = sessionStorage.getItem("user")
this.form = JSON.parse(str)
},
methods: {
update() {
request.put("/user/person", this.form).then(res => {
console.log(res)
if(res.code === '0'){
this.$message({
type: "success",
message: "更新成功"
})
sessionStorage.setItem("user", JSON.stringify(res.data))
}else {
this.$message({
type: "error",
message: "res.msg"
})
}
})
}
}
}
</script>
<style scoped>
</style>
4.新增/user/person訪問,返回修改後的使用者資訊,用於更新sessionStorage裡的user
5.