elm上传图片,只能上传一张,隐藏+上传框
2024-10-20 09:31:59
效果:
上传后,隐藏+号,禁止继续上传;
移除当前已上传的后,重新显示+号,可以继续上传;
代码:
css : 隐藏上传的 + 号
变量:
注:
利用 hideUpload 控制 + 号的css
pngFilesList 为图片默认列表,(用于编辑时回显图片)
方法:
// 上传成功时,让+号隐藏,不能再继续上传
pngUpSuccess (response, file, fileList) {
this.ruleForm.pngUrl = response.data.path
this.hideUpload = true
this.$store.dispatch('setLoading', false)
},
pngUpError (file, fileList) {
this.$store.dispatch('setLoading', false)
},
// 上传前限制类型和大小
pngBeforeUpload (file) {
this.$store.dispatch('setLoading', true)
const isPNG = file.type === 'image/png'
const isJPG = file.type === 'image/jpeg'
const isJPEG = file.type === 'image/jpeg'
const isLt2M = file.size / 1024 / 1024 < 2
if (!isPNG && !isJPG && !isJPEG) {
this.$message({
message: '不接受此文件类型!',
type: 'error',
showClose: true
})
this.$refs.uploadpng.clearFiles()
this.$store.dispatch('setLoading', false)
return false
}
if (!isLt2M) {
this.$message({
message: '图片大小不能超过2M',
type: 'error',
showClose: true
})
this.$refs.uploadpng.clearFiles()
this.$store.dispatch('setLoading', false)
return false
}
},
// 移除文件后重新让 + 号 显示
pngonRemove () {
this.ruleForm.pngUrl = ''
this.hideUpload = false
},
最新文章
- es6 中增强的对象字面量
- Spring 定时器Quartz的用法
- for循环三个表达式的执行时间
- qt添加最小化和关闭按钮
- Weka算法Classifier-tree-J48源代码分析(一个)基本数据结构和算法
- org.apache.commons.httpclient
- 问题记录:android.os.NetworkOnMainThreadException异常
- GS连接事件
- C++不确定行为
- jQuery实现按键盘方向键翻页
- Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical
- 【2016北京集训测试赛(二)】 thr (树形DP)
- nginx session 配置失效解决
- P3402 最长公共子序列
- 微信破解,解密?How To Decrypt WeChat EnMicroMsg.db Database?
- 强化学习之Q-learning简介
- WebAPI Token 验证
- table中的td等长(不随内容大小变化)
- EXT 翻页后查询 页数不重置
- AngularJS 中的作用域
热门文章
- 函数:3ds max 给选择对象设置轴心点
- 复习第二点-2.基于注解的helloworld
- Excel列动态导出
- elementUI合并单元格
- 实验:两片ESP8266,分别做客户端和服务器,实现双向收发数据
- 常见报错——Uncaught TypeError: document.getElementsByClassName(...).addEventListener is not a function
- Spring 事务传播属性
- 5G工业智能网关助力智能制造开辟新赛道
- xh_零基础网站渗透第一部
- kafka配置内外网同时访问