How to use vue to view personal information and change passwords
This time I will show you how to use vue to view personal information and change passwords. What are the precautions for using vue to view personal information and change passwords? The following is a practical case. Let’s take a look. .
The following code introduces Vue to implement personal information viewing and password modification functions. The specific code is as follows:
//用了element组件,自己要加载和引入 <template> <p class="all-container"> <p class="all-container-padding bg" > <el-tabs v-model="activeName" @tab-click="handleClick"> <el-tab-pane label="基本信息" name="first"> <el-form :model="userlist" :rules="rules" ref="EditorUserForms"> <el-form-item label="头像" prop="avatar_url" :label-width="formLabelWidth"> <el-upload class="avatar-uploader" action="//shujiaoke.oss-cn-hangzhou.aliyuncs.com" :before-upload="beforeupload" :data="uploadParm" :show-file-list="false" :on-success="handleUpSuccess"> <img v-if="userlist.avatar_url" :src="userlist.avatar_url" class="avatar"> <i v-else class="el-icon-plus avatar-uploader-icon " style="width:80px;height:80px;"></i> </el-upload> </el-form-item> <el-form-item label="用户名" prop="username" :label-width="formLabelWidth"> <el-col :span="8"> <el-input v-model="userlist.username" disabled ></el-input></el-col> </el-form-item> <el-form-item label="电话" prop="phone" :label-width="formLabelWidth"> <el-col :span="8"> <el-input v-model="userlist.phone" placeholder="请输入电话"></el-input></el-col> </el-form-item> <el-form-item label="邮箱" prop="email" :label-width="formLabelWidth"> <el-col :span="8"> <el-input v-model="userlist.email" placeholder="请输入邮箱"></el-input></el-col> </el-form-item> <el-form-item label="用户角色" prop="full_name" :label-width="formLabelWidth"> <el-col :span="8"> <el-input v-model="userlist.full_name" disabled ></el-input> </el-col> </el-form-item> </el-form> <p class="grid-content bg-purple"> <el-button type="primary" @click="EditorUserClick('userlist')" >保存</el-button> </p> </el-tab-pane> <el-tab-pane label="修改密码" name="second"> <el-form :model="ruleForm" :rules="rules" ref="ruleForm"> <el-form-item label="原密码" prop="pass" :label-width="formLabelWidth"> <el-col :span="8"> <el-input v-model="ruleForm.pass" placeholder="请输入原密码" type="password"></el-input></el-col> </el-form-item> <el-form-item label="新密码" prop="newpass" :label-width="formLabelWidth"> <el-col :span="8"><el-input v-model="ruleForm.newpass" placeholder="请输入新密码" id="newkey" type="password"></el-input></el-col> </el-form-item> <el-form-item label="重复新密码" prop="checknewpass" :label-width="formLabelWidth"> <el-col :span="8"> <el-input v-model="ruleForm.checknewpass" placeholder="请再次输入新密码" id='newkey1' type="password"></el-input></el-col> </el-form-item> </el-form> <p class="grid-content bg-purple"> <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button> </p> </el-tab-pane> </el-tabs> </p> </p> </template> <script> //这些不要在意,这些是我们自定义的接口,用的时候就直接拿来了 import {fetchAll,fetchByID,fetchList,postData,putData,deleteByID,deleteAllByID,guid,bytesToSize} from "@/api/dbhelper"; //这一步很重要,一般我们直接从后台拿过来输出来会是在data里面,但是我发现却在store里面,这里就要用到vuex import { mapGetters } from "vuex"; export default { data() { /*****检验两次密码是否一致***/ var validatePass = (rule, value, callback) => { if (value === "") { callback(new Error("请输入密码")); } else { if (this.ruleForm.checknewpass !== "") { this.$refs.ruleForm.validateField("checknewpass"); } callback(); } }; var validatePass2 = (rule, value, callback) => { if (value === "") { callback(new Error("请再次输入密码")); } else if (value !== this.ruleForm.newpass) { callback(new Error("两次输入密码不一致!")); } else { callback(); } }; return { uploadParm: {}, //图片的上传 ruleForm: {},//修改密码的表单 activeName: "first", loading: true, baseUrl: process.env.BASE_API, userlist: {},//用户信息表单 formLabelWidth: "150px", /***校验***/ rules: { phone: [ { required: true, message: "请输入电话号码" }, { pattern: /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/, message: "手机格式不对" } ], email: [ { required: true, message: "请输入电子邮箱" }, { pattern: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/, message: "请输入有效的邮箱" } ], pass: [ { required: true, trigger: "blur", message: "请输入密码" } ], newpass: [ { validator: validatePass, trigger: "blur" } ], checknewpass: [ { validator: validatePass2, trigger: "blur" } ] } }; }, created() { this.getUser(); this.upload(); }, computed: { ...mapGetters(["username"]) }, methods: { //获取个人用户的信息 getUser() { postData("接口", this.username).then(response => { if (response.status === 200) { this.userlist = response.data; this.loading = false; console.log(this.userlist, 9696); } else { this.$message({ message: "获取信息失败," + response.message, type: "error" }); } }); }, //tab切换 handleClick(tab, event) { console.log(tab, event); }, //上传参数图片初始化 upload() { var currentTimeStamp = new Date().getTime() / 1000; if ( this.uploadParams == null || this.uploadParams.expire + 3 < currentTimeStamp ) { this.$store .dispatch("GetUploadParams") .then(req => { this.uploadParm = req.data; }) .catch(err => { this.$message({ message: err.message, type: "warning" }); }); } else { this.uploadParm = this.uploadParams; } }, //上传之前 beforeupload(file) { this.uploadParm.key = this.uploadParm.dir + guid(); // console.log(this.uploadParm) }, //图片上传上传成功 handleUpSuccess(response, file, fileList) { var newfile = { name: file.name, type: file.raw.type, size: bytesToSize(file.size), url: this.uploadParm.key }; postData("file", newfile).then(response => { if (response.status == 200) { this.$message({ message: "修改成功", type: "success" }); this.userlist.style_file_id = response.data.id; this.userlist.avatar_url = this.baseUrl + response.data.url; } else { this.$message({ message: "修改失败", type: "error" }); } }); console.log(this.userlist); }, //修改密码 submitForm(ruleForm) { var obj = { username: this.username, oldpwd: this.ruleForm.pass, newpwd: this.ruleForm.newpass }; console.log(obj); postData("接口", obj).then(response => { if (response.status == 200) { this.$message({ message: "保存成功", type: "success" }); } else { this.$message({ message: "修改失败" + response.message, type: "error" }); } }); }, // 编辑提交的方法 EditorUserClick() { this.$refs.EditorUserForms.validate(valid => { if (valid) { console.log(this.userlist); putData("接口", this.userlist).then(response => { if (response.status == 200) { this.$message({ message: "编辑成功", type: "success" }); } else { this.$message({ message: "修改失败" + response.message, type: "error" }); } }); } }); } } }; </script>
I believe you have mastered the method after reading the case in this article. Please come for more exciting information. Pay attention to other related articles on php Chinese website!
Recommended reading:
How to use Vue to implement tree view data
What are the methods for JS to implement DOM tree traversal?
The above is the detailed content of How to use vue to view personal information and change passwords. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

Realizing love animation effects through Java code In the field of programming, animation effects are very common and popular. Various animation effects can be achieved through Java code, one of which is the heart animation effect. This article will introduce how to use Java code to achieve this effect and give specific code examples. The key to realizing the heart animation effect is to draw the heart-shaped pattern and achieve the animation effect by changing the position and color of the heart shape. Here is the code for a simple example: importjavax.swing.

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

1. First, open the enterprise WeChat software you downloaded on your mobile phone. When logging in, there are two ways to choose: one is to use WeChat ID, the other is to use mobile phone number. 3. At this time, the enterprise administrator needs to add your mobile phone number in the background, and then Enterprise WeChat will identify the enterprise based on your mobile phone number. Then display your business and click the Enter Business option below. 4. Then you can enter the use of functions in the software. It can be said that the most important thing is that your mobile phone number must be added to the enterprise by the administrator, otherwise it will not be available.

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

Implementing exact division operations in Golang is a common need, especially in scenarios involving financial calculations or other scenarios that require high-precision calculations. Golang's built-in division operator "/" is calculated for floating point numbers, and sometimes there is a problem of precision loss. In order to solve this problem, we can use third-party libraries or custom functions to implement exact division operations. A common approach is to use the Rat type from the math/big package, which provides a representation of fractions and can be used to implement exact division operations.

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these
