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 ...
随机推荐
- jsp+servlet实战项目
第一步:新建maven项目,项目中添加dao,entity,service,servlet,util包第二步:导入依赖 第三步:数据库建表 第四步:entity实体包(疯转) 第五步:在util工具包 ...
- mysql拓展
事务定义 就是将一组SQL语句放在同一批次内去执行 如果一个sql语句出错,则改批次内的所有sql都将被取消执行 (1)原子性 一个事务要么全部提交成功,要么全部失败回滚,不能只执行其中的一部分操作, ...
- 2.0 Python 数据结构与类型
数据类型是编程语言中的一个重要概念,它定义了数据的类型和提供了特定的操作和方法.在 python 中,数据类型的作用是将不同类型的数据进行分类和定义,例如数字.字符串.列表.元组.集合.字典等.这些数 ...
- What...MiniGPT-4居然开源了,提前感受 GPT-4 的图像对话能力!
说在前面的话: 一个月前,OpenAI向外界展示了GPT-4如何通过手绘草图直接生成网站,令当时的观众瞠目结舌. 在GPT-4发布会之后,相信大家对ChatGPT的对话能力已有所了解.圈内的朋友们应该 ...
- 产品代码都给你看了,可别再说不会DDD(四):代码工程结构
这是一个讲解DDD落地的文章系列,作者是<实现领域驱动设计>的译者滕云.本文章系列以一个真实的并已成功上线的软件项目--码如云(https://www.mryqr.com)为例,系统性地讲 ...
- 开源社区赋能,Walrus 用户体验再升级
基于平台工程理念的应用管理平台 Walrus 已于上月正式开源,目前在 GitHub 已收获 177 颗星 Walrus 希望打造简洁清爽的应用部署与管理体验,帮助研发与运维团队减少"内耗& ...
- 织梦tag怎么显示每个tag相应的文章数量
有些时候我们想实现类似于wordpress那样的tag,就是在显示tag的链接和tag名的同时,还能显示每个tag关联的文章的数量.如下图所示: 这就需要修改/include/taglib/tag.l ...
- Python爬虫-IP隐藏技术与代理爬取
在进行爬虫程序开发和运行时,常常会遇到目标网站的反爬虫机制,最常见的就是IP封禁,这时需要使用IP隐藏技术和代理爬取. 一.IP隐藏技术 IP隐藏技术,即伪装IP地址,使得爬虫请求的IP地址不被目标网 ...
- Intrusion Detection Using Convolutional Neural Networks for Representation Learning 笔记
Intrusion Detection Using Convolutional Neural Networks for Representation Learning 2.2 实验数据的预处理 为了确 ...
- 使用 Sealos 构建低成本、高效能的私有云
这个时候谈论私有云似乎有点反直觉?大部分人认知不是上云是大趋势嘛?我也比较认可上云,不过私有云也是云,今天给大家带来一个新的选择 -- 用云,只需一个 Sealos 就够了. 看看我们怎么做到更低的成 ...