vue+element-ui小笔记
1.图片加载失败,给默认图,两种解决方法:
方法一:
给img标签加 onerror指令,然后在data中给 errorGoodsImg 赋值,根据自己所需图片路径赋值
<img :src="imgSrc+scope.row.fileId" id="avatarImg" v-if="scope.row.fileId" :onerror="errorGoodsImg">
小颖的目录:

data中,errorGoodsImg的值如下:
errorGoodsImg: 'this.src="' + require('../assets/images/new.jpg') + '"',
方法二:
调用 element-ui 中的 <el-image> 标签,可通过slot = error可自定义加载失败内容
eg:
<el-image v-if="userInfo.credentialsFileId" style="width: 75px; height: 115px" :src="imgSrc+userInfo.credentialsFileId" :preview-src-list="srcList">
<div slot="error" class="image-slot">
<i class="el-icon-picture-outline"></i>
</div>
</el-image>
2.form表单中,输入框加回车事件,页面刷新,如何解决?
解决方法就是在form中添加:@submit.native.prevent
示例:
html代码:
<template>
<div class="ceshi-form-tem right-content-tem">
<el-form ref="form" :model="userInfo" label-width="100px" class="userInfo-form" @submit.native.prevent>
<el-row>
<el-col :span="12">
<p class="form-title-tem">基本信息</p>
</el-col>
<el-col :span="12" class="txt-right">
<el-form-item>
<el-button type="primary" @click="onSubmit('form')" :loading="btnUserLoading">
保存
</el-button>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="头像">
<el-upload
style="width: 30%"
action="https://jsonplaceholder.typicode.com/posts/"
accept=".jpg,.png"
:on-remove="handleRemoveAvatar"
:beforeUpload="beforeAvatarUpload"
:on-error="onError"
:on-success="onSuccess"
:limit="1">
<img v-if="userInfo.avatar" :src="userInfo.avatar" :onerror="errorGoodsImg"
class="userInfo-avatar">
<img v-else src="../assets/img/tu4.png" class="userInfo-avatar">
</el-upload>
</el-form-item>
<el-form-item
label="昵称"
prop="nickname">
<p v-if="!userInfoEdit.nickname">{{userInfo.nickname}}
<i class="el-icon-edit" @click="showInput('nickname')"></i>
</p>
<el-input ref="customerInput" v-else maxlength="6" placeholder="请输入昵称" v-model="userInfo.nickname"
@keyup.enter.native="handleInputConfirm('nickname')"
@blur="handleInputConfirm('nickname')"></el-input>
</el-form-item>
<el-form-item label="姓名">
<p>{{userInfo.username}}</p>
</el-form-item>
<el-form-item label="性别">
<el-radio-group v-model="userInfo.sex" @change="changeSex">
<el-radio :label="1">男</el-radio>
<el-radio :label="0">女</el-radio>
</el-radio-group>
</el-form-item>
<!--普通用户-->
<el-form-item label="所属机构">
<p v-if="!userInfoEdit.organizationName">{{userInfo.organizationName}}<i class="el-icon-edit" @click="showInput('organizationName')"></i></p>
<el-input ref="customerInput" v-if="userInfoEdit.organizationName" maxlength="6" placeholder="请输入所属机构"
v-model="userInfo.organizationName"
@keyup.enter.native="handleInputConfirm('organizationName')"
@blur="handleInputConfirm('organizationName')"></el-input>
</el-form-item>
</el-form>
</div>
</template>
js代码:
<script>
export default {
name: "formCeshi",
data(){
return {
btnUserLoading: false,
errorGoodsImg: 'this.src="' + require('../assets/img/tu4.png') + '"',
userInfo: {
avatar: '',
nickname: 'v',
username: '测试',
sex: 1,
organizationName: '杀杀杀'
},
userInfoEdit: {
nickname: false,
organizationName: false
},
haveChange: false
}
},
mounted() {
this.haveChange = false
},
methods: {
onSubmit(formName) {
const that = this
if (!that.haveChange) {
that.$message({
message: '当前没有任何修改',
type: 'warning'
});
return
}
that.btnUserLoading = true
that.$refs[formName].validate((valid) => {
if (valid) {
that.btnUserLoading = false
// 调接口
} else {
that.btnUserLoading = false
return false;
}
});
},
showInput(key) {
switch (key) {
case'nickname':
this.userInfoEdit.nickname = true;
break
case'organizationName':
this.userInfoEdit.organizationName = true;
break
}
this.$nextTick(function () {
this.$refs.customerInput.$el.querySelector('input').focus();
});
},
handleInputConfirm(key) {
this.haveChange = true
switch (key) {
case'nickname':
this.userInfoEdit.nickname = false;
break
case'organizationName':
this.userInfoEdit.organizationName = false;
break
}
},
handleRemoveAvatar(file, fileList) {
this.userInfo.avatar = ''
},
beforeAvatarUpload(file) {
let fileend = file.name.substring(file.name.lastIndexOf("."))
//jpg、png、bmp
const isZip = (fileend === '.jpg' || file.type === 'jpg') || (fileend === '.png' || file.type === 'png')
if (!isZip) {
this.$message.error('您只能上传jpg、png格式的图片!')
}
const isLt2G = file.size / 1024 / 1024 < 1;
if (!isLt2G) {
this.$message.error('上传的图片大小必须小于1MB!')
}
return isZip && isLt2G
},
onSuccess(file, res, fileList) {
if (res.response.code != 200) {
this.$message.error('上传头像失败');
} else {
this.haveChange = true
this.userInfo.avatar = URL.createObjectURL(file.raw);
}
},
onError(err, file, fileList) {
const errMsg = JSON.parse(err.message)
this.$message.error(errMsg.msg ? errMsg.msg : '上传头像失败');
},//修改性别
changeSex() {
this.haveChange = true
}
}
}
</script>
css
<style scoped>
form.userInfo-form {
width: 400px;
margin: 40px auto 0 auto;
}
img.userInfo-avatar {
width: 48px;
height: 48px;
border-radius: 50%;
}
</style>
3.使用在线主题生成工具,修改element自定义主题色
打开在线主题编辑器,在该页面中根据自己的需求,更改颜色,修改完后,下载主题包,然后在项目中引入就可以了。

持续更新.......................................
秀两张我家仔仔的盛世美颜:


vue+element-ui小笔记的更多相关文章
- vue + element ui 实现实现动态渲染表格
前言:之前需要做一个页面,能够通过表名动态渲染出不同的表格,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9786326.html 网站地址:我的 ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
- vue+element ui 的表格列使用组件
前言:工作中用到 vue+element ui 的前端框架,有这个场景:很多表格的列有许多一样的,所以考虑将列封装为组件.转载请注明出处:https://www.cnblogs.com/yuxiaol ...
- Vue+element ui table 导出到excel
需求: Vue+element UI table下的根据搜索条件导出当前所有数据 参考: https://blog.csdn.net/u010427666/article/details/792081 ...
- 基于vue(element ui) + ssm + shiro 的权限框架
zhcc 基于vue(element ui) + ssm + shiro 的权限框架 引言 心声 现在的Java世界,各种资源很丰富,不得不说,从分布式,服务化,orm,再到前端控制,权限等等玲琅满目 ...
- 分享一个自搭的框架,使用Spring boot+Vue+Element UI
废弃,新的:https://www.cnblogs.com/hackyo/p/10453243.html 特点:前后端分离,可遵循restful 框架:后端使用Spring boot,整合了aop.a ...
- Vue + Element UI 实现权限管理系统
Vue + Element UI 实现权限管理系统 前端篇(一):搭建开发环境 https://www.cnblogs.com/xifengxiaoma/p/9533018.html
- vue+element ui 的上传文件使用组件
前言:工作中用到 vue+element ui 的前端框架,使用到上传文件,则想着封装为组件,达到复用,可扩展.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9 ...
- vue+element ui 的tab 动态增减,切换时提示用户是否切换
前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui 有一个 bug,这里记录一下如何实现.转载 ...
- 基于 vue+element ui 的cdn网站(多页面,都是各种demo)
前言:这个网站持续更新中...,有网上预览,github上也有源码,喜欢记得star哦,欢迎留言讨论. 网站地址:我的个人vue+element ui demo网站 github地址:yuleGH g ...
随机推荐
- 新一代开源流数据湖平台Apache Paimon入门实操-下
@ 目录 实战 写表 插入和覆盖数据 更新数据 删除数据 Merge Into 查询表 批量查询 时间旅行 批量增量查询 流式查询 时间旅行 ConsumerID 查询优化 系统表 表指定系统表 分区 ...
- Kali开机启动模式修改
kali Linux安装之后默认启动图形化界面,为了减轻系统负担,可以修改启动进入字符界面. 具体步骤如下: 1.打开引导配置文件 vim /etc/default/grub 2.修改GRUB_CMD ...
- [ABC146F] Sugoroku
2023-02-27 题目 题目传送门 翻译 翻译 难度&重要性(1~10):5 题目来源 AtCoder 题目算法 贪心 解题思路 对于第 ii 个点,只要到达 \(s_{i+1}\cdot ...
- 使用API数据接口获取商品详情数据的流程
API数据接口是开发者获取第三方平台数据的一种方式,使用API接口可以快速地获取海量的商品详情数据,相比其他方式更加高效.实时.下面将介绍使用API数据接口获取商品详情数据的主要流程和步骤: 申请AP ...
- excel的烦恼
Smiling & Weeping ---- 他未对我好半分,偏巧这感情疯长似野草 题目链接:https://www.matiji.net 思路:与新三进制2思路相似,转化为纯26进制,然后往 ...
- Netty+WebSocket整合STOMP协议
1.STOMP协议简介 常用的WebSocket协议定义了两种传输信息类型:文本信息和二进制信息.类型虽然被确定,但是他们的传输体是没有规定的,也就是说传输体可以自定义成什么样的数据格式都行,只要客户 ...
- Webpack性能优化 SplitChunksPlugin的使用详解
使用前景 在vue.react等使用webpack为项目打包工具的前端项目,在开发过程中,随着项目功能的逐渐增加,项目整体体积的不断增加,打包的时长和打包后部署的项目体积也在不停的增长,这样可能会导致 ...
- DICOM PS3.7 2021a - Message Exchange
PS3.7 DICOM PS3.7 2021a - Message Exchange DICOM Standards Committee Copyright 2021 NEMA A DICOM pub ...
- Jmeter内的参数有文件时,如何传参?
文件类型:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 尊重原创,转载请注明出处,谢谢!!
- ABC319 A-E 题解
A 用 map <string, int> 将名字对应的值存下来即可. 赛时代码 B 按照题意暴力模拟,注意细节. 赛时代码 C 答辩题,卡了我半个小时. 枚举 \(1\sim 9\) 的 ...