current position:Home>Springboot + Vue integrates personal center, avatar modification, data linkage and password modification
Springboot + Vue integrates personal center, avatar modification, data linkage and password modification
2022-04-29 20:46:42【Programmer Qingge】
Source code :https://gitee.com/xqnode/pure-design/tree/master
Learning video :https://www.bilibili.com/video/BV1U44y1W77D
Start to explain
Drop down menu of personal information :
<el-dropdown style="width: 150px; cursor: pointer; text-align: right">
<div style="display: inline-block">
<img :src="user.avatarUrl" alt="" style="width: 30px; border-radius: 50%; position: relative; top: 10px; right: 5px">
<span>{
{ user.nickname }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
</div>
<el-dropdown-menu slot="dropdown" style="width: 100px; text-align: center">
<el-dropdown-item style="font-size: 14px; padding: 5px 0">
<router-link to="/password"> Change Password </router-link>
</el-dropdown-item>
<el-dropdown-item style="font-size: 14px; padding: 5px 0">
<router-link to="/person"> Personal information </router-link>
</el-dropdown-item>
<el-dropdown-item style="font-size: 14px; padding: 5px 0">
<span style="text-decoration: none" @click="logout"> sign out </span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
Routing settings ( static state )
const manageRoute = {
path: '/', name: 'Manage', component: () => import('../views/Manage.vue'), redirect: "/home", children: [
{
path: 'person', name: ' Personal information ', component: () => import('../views/Person.vue')},
{
path: 'password', name: ' Change Password ', component: () => import('../views/Password.vue')},
] }
newly build Person.vue page
<template>
<div>
<el-card style="width: 600px">
<el-form label-width="80px" size="small">
<div style="text-align: center; margin: 10px 0">
<el-upload class="avatar-uploader" action="http://localhost:9090/file/upload" :show-file-list="false" :on-success="handleAvatarSuccess" >
<img v-if="form.avatarUrl" :src="form.avatarUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</div>
<el-form-item label=" user name ">
<el-input v-model="form.username" autocomplete="off" disabled></el-input>
</el-form-item>
<el-form-item label=" nickname ">
<el-input v-model="form.nickname" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label=" mailbox ">
<el-input v-model="form.email" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label=" Telephone ">
<el-input v-model="form.phone" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label=" Address ">
<el-input v-model="form.address" autocomplete="off"></el-input>
</el-form-item>
</el-form>
<div style="text-align: center">
<el-button type="primary" @click="save"> indeed set </el-button>
</div>
</el-card>
</div>
</template>
Then write the request interface JS:
<script>
export default {
name: 'Person',
data() {
return {
form: {
},
user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {
}
}
},
created() {
this.load()
},
methods: {
load() {
const username = this.user.username
if (!username) {
this.$message.error(" Currently unable to get user information !")
return
}
this.request.get("/user/username/" + username).then(res => {
this.form = res.data
})
},
save() {
this.request.post("/user", this.form).then(res => {
if (res.code === '200') {
this.$message.success(" Saved successfully ")
this.dialogFormVisible = false
this.load()
this.$emit('refreshUser')
} else {
this.$message.error(" Save failed ")
}
})
},
handleAvatarSuccess(res) {
// res Is the path of the file
this.form.avatarUrl = res
}
}
}
</script>
I ask you to check your request interface , This will prevent 404 Error of !
Manage.vue Changes that need to be made :
// Pass in user Object to Header Inside the component
<Header :collapseBtnClass="collapseBtnClass" @asideCollapse="collapse" :user="user" />
data() {
return {
user: {}
}
}
created() {
// Get the latest from the background User data
this.getUser()
},
// stay methos Write a function in it , Get the latest data of the user
getUser() {
let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : ""
if (username) {
// Get... From the background User data
this.request.get("/user/username/" + username).then(res => {
// Reassign the latest in the background User data
this.user = res.data
})
}
}
Header.vue Changes that need to be made
// Define a user Attribute accept from Manage.vue incoming user object
props: {
user: Object
},
// And then in Header This place of use :
<el-dropdown style="width: 150px; cursor: pointer; text-align: right">
<div style="display: inline-block">
<img :src="user.avatarUrl" alt="" style="width: 30px; border-radius: 50%; position: relative; top: 10px; right: 5px">
<span>{
{ user.nickname }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
</div>
<el-dropdown-menu slot="dropdown" style="width: 100px; text-align: center">
<el-dropdown-item style="font-size: 14px; padding: 5px 0">
<router-link to="/password"> Change Password </router-link>
</el-dropdown-item>
<el-dropdown-item style="font-size: 14px; padding: 5px 0">
<router-link to="/person"> Personal information </router-link>
</el-dropdown-item>
<el-dropdown-item style="font-size: 14px; padding: 5px 0">
<span style="text-decoration: none" @click="logout"> sign out </span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
The last step , stay Person.vue The trigger method is written in it :
this.$emit('refreshUser')
And then in Manage Make corresponding modifications in it :
<router-view @refreshUser="getUser" />
Change Password :
<template>
<el-card style="width: 500px;">
<el-form label-width="120px" size="small" :model="form" :rules="rules" ref="pass">
<el-form-item label=" Original password " prop="password">
<el-input v-model="form.password" autocomplete="off" show-password></el-input>
</el-form-item>
<el-form-item label=" New password " prop="newPassword">
<el-input v-model="form.newPassword" autocomplete="off" show-password></el-input>
</el-form-item>
<el-form-item label=" Confirm the new password " prop="confirmPassword">
<el-input v-model="form.confirmPassword" autocomplete="off" show-password></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="save"> indeed set </el-button>
</el-form-item>
</el-form>
</el-card>
</template>
<script> export default {
name: "Password", data() {
return {
form: {
}, // username, password, newPassword, confirmNewPassword this 4 Attributes user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {
}, rules: {
password: [ {
required: true, message: ' Please enter the original password ', trigger: 'blur' }, {
min: 3, message: ' Not less than in length 3 position ', trigger: 'blur' } ], newPassword: [ {
required: true, message: ' Please enter the new password ', trigger: 'blur' }, {
min: 3, message: ' Not less than in length 3 position ', trigger: 'blur' } ], confirmPassword: [ {
required: true, message: ' Please input a password ', trigger: 'blur' }, {
min: 3, message: ' Not less than in length 3 position ', trigger: 'blur' } ], } } }, created() {
this.form.username = this.user.username }, methods: {
save() {
this.$refs.pass.validate((valid) => {
if (valid) {
// legal if (this.form.newPassword !== this.form.confirmPassword) {
this.$message.error("2 The new password you entered is different ") return false } this.request.post("/user/password", this.form).then(res => {
if (res.code === '200') {
this.$message.success(" Modification successful ") this.$store.commit("logout") } else {
this.$message.error(res.msg) } }) } }) }, } } </script>
<style> .avatar-uploader {
text-align: center; padding-bottom: 10px; } .avatar-uploader .el-upload {
border: 1px dashed #d9d9d9; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; } .avatar-uploader .el-upload:hover {
border-color: #409EFF; } .avatar-uploader-icon {
font-size: 28px; color: #8c939d; width: 138px; height: 138px; line-height: 138px; text-align: center; } .avatar {
width: 138px; height: 138px; display: block; } </style>
backstage :
import lombok.Data;
@Data
public class UserPasswordDTO {
private String username;
private String phone;
private String password;
private String newPassword;
}
Controller Interface
@PostMapping("/password") // /user/password
public Result password(@RequestBody UserPasswordDTO userPasswordDTO) {
userService.updatePassword(userPasswordDTO);
return Result.success();
}
Business class UserServiceImpl.java:
@Override
public void updatePassword(UserPasswordDTO userPasswordDTO) {
int update = userMapper.updatePassword(userPasswordDTO);
if (update < 1) {
throw new ServiceException(Constants.CODE_600, " Wrong password ");
}
}
data Mapper layer :
@Update("update sys_user set password = #{newPassword} where username = #{username} and password = #{password}")
int updatePassword(UserPasswordDTO userPasswordDTO);
well , thus Personal center 、 Modify the head image 、 Data linkage 、 The four contents of password modification are integrated ! And the flower ~
copyright notice
author[Programmer Qingge],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291844288068.html
The sidebar is recommended
- Talking about nodejs server
- Node. js&lt; I & gt—— Encounter node and repl usage
- Vue basic API: calculation attribute + filter + listener
- 1-stm32 + mn316 (nb-iot) remote upgrade OTA (self built Internet of things platform) - STM32 uses HTTP to download program files and upgrade programs through mn316 (MCU program rotation check and update)
- Vue Axios response interception
- vue3 ref
- How does Vue transfer the data from the parent component to the child component intact?
- The back-end interface developed by springboot in idea and the Vue front-end developed by vscode. How to integrate Vue code into springboot?
- Fried cold rice series 4: scope and closure in JavaScript
- Typescript type compatibility learning
guess what you like
Summary of bugs encountered in front-end development
Chrome developer tool: performance analysis using web panel
Collation of common semantic elements and global attributes in HTML
Life cycle in Vue
5.1 fear of traffic jam? With a budget of less than 100000, these cars with adaptive cruise make it easy for you to travel
Docker compose deploy nginx configure SSL
The content of element type “mapper“ must match “(cache-ref|cache|resultMap*|parameterMap*|sql*|inse
-CSS-
Vue uses two-way binding to implement the user registration page
Is Infiniti qx60 worth less than 400000 yuan? It depends on the discount
Random recommended
- "Element Fangjian: first heart version" public beta welfare release, go to the great God app to receive red envelopes and prizes
- What is the role of webpack cli in webpack packaging
- Vue3 configuration method using Axios
- How to configure Google reverse proxy on nginx server
- Volume comparison between Vue and react
- What are the three ways to define components in react
- How to install and configure the blogging program Typecho on the nginx server
- How to configure load balancing for TCP in nginx server
- How to configure nginx server under Windows system
- How to configure AB to do stress testing for nginx server
- Analysis of location configuration in nginx server
- How to integrate Linux and redmine into the redmine system
- How to build the production environment of nginx + PHP with PHP FPM
- How to optimize the performance of nginx supporting SSL
- How to configure nginx server to prevent flood attack
- [Axios learning] basic use of Axios
- [Axios learning] Axios request mode, concurrent request, global configuration, instance and interceptor
- Use the virtual queue implemented by list to view the first element of the queue in Python without taking it out
- This dependency was not found and to install it, you can run: NPM install score JS
- Front end serial communication
- leedcode. 203 remove linked list elements
- Dialogue with Liu Dayong, information director of Jiuyang shares: key elements of enterprise digital intelligence transformation
- JQuery gets the method summary of parent element, child element and brother element
- Web Security: analysis of DOM XSS vulnerability source code of jquery
- The sales volume of Genesys in China is 283, less than 300, and the domestic sales volume is dismal
- This beast was blessed with skills to test drive the DHT version of Harvard beast
- Bootstrap and jQuery implement tree structure
- Fried cold rice series 5: recursion in JavaScript?
- 2022 open source summer | serverless devs accompany you to "become stronger"
- How to create a high-performance full screen red envelope rain
- Detailed process of spring boot free HTTPS project configuration!
- Create a simple vue3 project
- How to create a simple react project
- Vue custom text background
- Front end HTML
- leetcode:462. Minimum number of moves to make array elements equal II [sort + find the middle]
- City selection (provincial and urban cascade) plug-in v-distpicker component details and a full set of usage
- How to use js to achieve such a drag and zoom effect
- Quick report ~ node JS 18 coming! Let's see what's new
- Easily manage projects using Vue UI graphical interface