1.图片加载失败,给默认图

2.form表单中,输入框加回车事件,页面刷新,如何解决?

3.使用在线主题生成工具,修改element自定义主题色

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小笔记的更多相关文章

  1. vue + element ui 实现实现动态渲染表格

    前言:之前需要做一个页面,能够通过表名动态渲染出不同的表格,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9786326.html 网站地址:我的 ...

  2. vue + element ui 表格自定义表头,提供线上demo

    前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...

  3. vue+element ui 的表格列使用组件

    前言:工作中用到 vue+element ui 的前端框架,有这个场景:很多表格的列有许多一样的,所以考虑将列封装为组件.转载请注明出处:https://www.cnblogs.com/yuxiaol ...

  4. Vue+element ui table 导出到excel

    需求: Vue+element UI table下的根据搜索条件导出当前所有数据 参考: https://blog.csdn.net/u010427666/article/details/792081 ...

  5. 基于vue(element ui) + ssm + shiro 的权限框架

    zhcc 基于vue(element ui) + ssm + shiro 的权限框架 引言 心声 现在的Java世界,各种资源很丰富,不得不说,从分布式,服务化,orm,再到前端控制,权限等等玲琅满目 ...

  6. 分享一个自搭的框架,使用Spring boot+Vue+Element UI

    废弃,新的:https://www.cnblogs.com/hackyo/p/10453243.html 特点:前后端分离,可遵循restful 框架:后端使用Spring boot,整合了aop.a ...

  7. Vue + Element UI 实现权限管理系统

    Vue + Element UI 实现权限管理系统 前端篇(一):搭建开发环境 https://www.cnblogs.com/xifengxiaoma/p/9533018.html

  8. vue+element ui 的上传文件使用组件

    前言:工作中用到 vue+element ui 的前端框架,使用到上传文件,则想着封装为组件,达到复用,可扩展.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9 ...

  9. vue+element ui 的tab 动态增减,切换时提示用户是否切换

    前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui  有一个 bug,这里记录一下如何实现.转载 ...

  10. 基于 vue+element ui 的cdn网站(多页面,都是各种demo)

    前言:这个网站持续更新中...,有网上预览,github上也有源码,喜欢记得star哦,欢迎留言讨论. 网站地址:我的个人vue+element ui demo网站 github地址:yuleGH g ...

随机推荐

  1. 【笔记】- 【美团1万台 Hadoop 集群 YARN 的调优之路】

    原文:美团1万台 Hadoop 集群 YARN 的调优之路 背景 架构 YARN架构 资源抽象 YARN调度架构 资源抽象 调度流程 作业的组织方式 核心调度流程 指标 业务指标:有效调度 系统性能指 ...

  2. coredns使用etcd

    前言 CoreDNS使用ETCD存储主机记录.etcd安装略过. Corefile内容 .:53 { # 绑定本机IP bind 192.168.1.2 # etcd地址 etcd { path /c ...

  3. nginx-http反向代理与负载均衡

    前言 反向代理服务器位于用户与目标服务器之间,但是对于用户而言,反向代理服务器就相当于目标服务器,即用户直接访问反向代理服务器就可以获得目标服务器的资源.同时,用户不需要知道目标服务器的地址,也无须在 ...

  4. 解密Prompt系列13. LLM Agent-指令微调方案: Toolformer & Gorilla

    上一章我们介绍了基于Prompt范式的工具调用方案,这一章介绍基于模型微调,支持任意多工具组合调用,复杂调用的方案.多工具调用核心需要解决3个问题,在哪个位置进行工具调用(where), 从众多工具中 ...

  5. 为什么NoSQL不支持事务

    为什么NoSQL不支持事务 1. 背景 看书<Neo4j权威指南>的时候,发现个问题:日常的NoSQL都不支持事务(ACID). 2. 问题 事务对数据的存储过程是有利的,既然事情是有利的 ...

  6. Web安全漏洞解决方案

    1.已解密的登录请求 推理: AppScan 识别了不是通过 SSL 发送的登录请求. 测试请求和响应: 1.1.1 产生的原因 登录接口,前端传入的密码参数没有经过md5的加密就直接传给了后端 1. ...

  7. 《最新出炉》系列初窥篇-Python+Playwright自动化测试-13-playwright操作iframe-下篇

    1.简介 通过前边两篇的学习,想必大家已经对iframe有了一定的认识和了解,今天这一篇主要是对iframe做一个总结,主要从iframe的操作(输入框.点击等等)和定位两个方面进行总结. 2.ifr ...

  8. MQ系列14:MQ如何做到消息延时处理

    MQ系列1:消息中间件执行原理 MQ系列2:消息中间件的技术选型 MQ系列3:RocketMQ 架构分析 MQ系列4:NameServer 原理解析 MQ系列5:RocketMQ消息的发送模式 MQ系 ...

  9. 集群部署专题之一:详解集群间SSH无密码登录配置步骤

    一.SSH简介 SSH(Secure Shell)是一种网络安全协议,通过加密和认证机制实现安全访问和文件传输等业务.传统远程登录和文件传输方式有Telnet或FTP,这两种方式都使用明文传输数据,存 ...

  10. 在线问诊 Python、FastAPI、Neo4j — 创建症状节点

    目录 症状数据 创建节点 附学习 电子病历中,患者主诉对应的相关检查,得出的诊断以及最后的用药情况.症状一般可以从主诉中提取. 症状数据 symptom_data.csv CSV 中,没有直接一行一个 ...