


Vue implements personal information viewing and password modification functions
This article introduces you to vue's implementation of personal information viewing and password modification functions through example code. The article also introduces vue's implementation of password display and hiding switching functions. It is very good and has certain reference value. Friends who are interested can join us. Let’s take a look
The following code will introduce you to vue’s implementation of 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 class="avatar lazy" src="/static/imghwm/default1.png" data-src="userlist.avatar_url" v-if="userlist.avatar_url" : alt="Vue implements personal information viewing and password modification functions" > <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>
Click to view vue to implement the password display and hide switching function
Related recommendations:
vue to implement WeChat authorized login steps detailed explanation
The above is the detailed content of Vue implements personal information viewing and password modification functions. For more information, please follow other related articles on the PHP Chinese website!

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software