八、vue使用element-ui组件
element-ui组件
1.引入element
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue'; Vue.use(ElementUI); const vue = new Vue({
el: '#app',
template: '<App/>',
components: {App}
}); export default vue;
2.table表格+Pagination分页
http://element-cn.eleme.io/#/zh-CN/component/table
http://element-cn.eleme.io/#/zh-CN/component/pagination
2.1分页使用:
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:pager-count="7"
:page-sizes="[5, 10, 15]"
:page-size="size"
:current-page="currentPage"
:total="count"
layout="total, sizes, prev, pager, next, jumper">
</el-pagination>
handleSizeChange(val) {//pageSize改变时回调
console.log(`每页 ${val} 条`);
this.size = val;
this.getCommodityList();
},
handleCurrentChange(val) {//currentPage改变时回调
console.log(`当前页: ${val}`);
this.currentPage = val;
this.getCommodityList();
},
2.2表格自定义排序
1.Table 上监听sort-change事件
@sort-change='sortChange'
2.自定义排序
sort-change方法自带三个参数,分别代表意义是:
column:当前列
prop:当前列需要排序的数据
order:排序的规则(升序、降序和默认[默认就是没排序])
sortChange(column, prop, order) {//自定义排序
console.log(column)
if (column.prop == null) {
this.sortName = '默认排序字段';
} else {
this.sortName = column.prop;
}
if (column.order == 'ascending') {
this.sortType = 'ASC';
} else {
this.sortType = 'DESC';
}
this.loadProductList();
}
3.需要排序的字段添加
sortable="custom"
4.合并单元格
https://blog.csdn.net/hefeng6500/article/details/82778680
3.文件上传(自定义上传)
http://element-cn.eleme.io/#/zh-CN/component/upload
el-upload默认选择文件就上传,可以通过:auto-upload='false'设置,
upload方法在上传文件中是以FormData的格式上传,可以通过http-request属性覆盖默认的上传行为。
使用base64转码后进行上传实现:
1.options:通过options参数可以拿到upload组件所有的参数。options.file则是操作的文件。
2.使用FileReader进行base64转码
editUploadPic(options) {
console.log(options)
if (!window.FileReader) {
console.error('你的浏览器不支持FileReader API,请使用更高级的浏览器!')
}
let fileReader = new FileReader();
let file = options.file;
if (file) {
fileReader.readAsDataURL(file);
}
fileReader.onload = () => {
let base64Str = fileReader.result;
options.onSuccess(base64Str, file)
}
},
3.通过:on-success="handleServiceAvatarScucess",文件上传成功时的钩子,进行赋值
handleServiceAvatarScucess(res, file) {//重写上传方法,转BASE64成功后,设置图片
this.ruleEditForm.thumbnail = res;
},
参考:ElementUI之el-upload实现base64上传
把上传的csv文件转json
上传文件之前的钩子before-upload进行操作,
使用papaparse插件进行csv转json
beforeUpload(file) {
let excelfileExtend = ".csv";//设置文件格式
let fileExtend = file.name.substring(file.name.lastIndexOf('.')).toLowerCase();
if (!excelfileExtend.includes(fileExtend)) {
this.$message.error('文件格式错误');
return false;
}
//csv2json
papaparse.parse(file, {
header: true,
complete: results => {
console.log(results.data);
let inventoryRequests = results.data;
}
})
return false;
},
4.js实现json转excel
封装模块
/**
* json转excel模块
*/ const JSONToExcelConvertor = (JSONData, FileName, ShowLabel) => {
//先转化json
var arrData = typeof JSONData != "object" ? JSON.parse(JSONData) : JSONData; var excel = "<table>"; //设置表头
var row = "<tr>";
for (var i = 0, l = ShowLabel.length; i < l; i++) {
row += "<td>" + ShowLabel[i].value + "</td>";
} //换行
excel += row + "</tr>"; //设置数据
for (var i = 0; i < arrData.length; i++) {
var row = "<tr>"; for (var index in arrData[i]) {
var value =
arrData[i][index].value === "." ? "" : arrData[i][index].value;
row += "<td style=\"mso-number-format:'\\@';\">" + value + "</td>";
} excel += row + "</tr>";
} excel += "</table>"; var excelFile =
"<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
excelFile +=
'<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
excelFile +=
'<meta http-equiv="content-type" content="application/vnd.ms-excel';
excelFile += '; charset=UTF-8">';
excelFile += "<head>";
excelFile += "<!--[if gte mso 9]>";
excelFile += "<xml>";
excelFile += "<x:ExcelWorkbook>";
excelFile += "<x:ExcelWorksheets>";
excelFile += "<x:ExcelWorksheet>";
excelFile += "<x:Name>";
excelFile += "{worksheet}";
excelFile += "</x:Name>";
excelFile += "<x:WorksheetOptions>";
excelFile += "<x:DisplayGridlines/>";
excelFile += "</x:WorksheetOptions>";
excelFile += "</x:ExcelWorksheet>";
excelFile += "</x:ExcelWorksheets>";
excelFile += "</x:ExcelWorkbook>";
excelFile += "</xml>";
excelFile += "<![endif]-->";
excelFile += "</head>";
excelFile += "<body>";
excelFile += excel;
excelFile += "</body>";
excelFile += "</html>"; var uri =
"data:application/vnd.ms-excel;charset=utf-8," +
encodeURIComponent(excelFile); var link = document.createElement("a");
link.href = uri; link.style = "visibility:hidden";
link.download = FileName + ".xls"; document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}; export const json2excel = (
header = new Array(),
content = new Array(),
title = new Date().getTime.toString
) => {
if (header instanceof Array == false) {
alert("表头必须是数组");
return false;
}
if (content instanceof Array == false) {
alert("内容必须是数组");
return false;
}
if (content[0] instanceof Array == false) {
alert("内容中的每一项必须是数组");
return false;
}
if (!(typeof title == "string" && title.constructor == String)) {
alert("表格名称必须为字符串");
return false;
}
let excel = {
header: new Array(),
data: new Array()
};
for (let value of header.values()) {
excel.header.push({
value: value,
type: "ROW_HEADER_HEADER",
datatype: "string"
});
}
for (let val of content.values()) {
let b = new Array();
for (let a of val) {
b.push({ value: a, type: "ROW_HEADER" });
}
excel.data.push(b);
}
JSONToExcelConvertor(excel.data, title, excel.header);
};
5.form表单
http://element-cn.eleme.io/#/zh-CN/component/form
八、vue使用element-ui组件的更多相关文章
- 整理目前支持 Vue 3 的 UI 组件库 (2021 年)
最近,让前端圈子振奋的消息莫过于 Vue 3.0 的发布,一个无论是性能还是 API 设计都有了重大升级的新版本.距离 Vue 3.0 正式版发布已经有一段时间了,相信相关生态周边库也正在适配新版本中 ...
- element ui组件的开始时间-结束时间验证
<el-date-picker v-model="seach.before" type="date" placeholder="开始时间&quo ...
- 关于vue.js element ui 表单验证 this.$refs[formName].validate()的问题
方法使用前需了解: 来自”和“小编的小提示: 首先打印一下this.$refs[formName],检查是否拿到了正确的需要验证的form. 其次在拿到了正确的form后,检查该form上添加 ...
- (Element UI 组件 Table)去除单元格底部的横线
Element UI 组件 Table 有一个属性 border,添加它可以增加纵向边框,但是无法控制横线边框,因此即使是最简单的 el-table,也会包含一个底部横线. 这个底部横线其实是一个 b ...
- vue.js相关UI组件收集
内容 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 ###UI组件 element ★9689 - 饿了么出品的Vue2的web UI工具套件 Vux ★6927 - 基于Vu ...
- vue-cli按需引入Element UI组件
一.环境 使用vue-cli搭建的环境 二.安装 babel-plugin-component npm install babel-plugin-component -D 三.修改.babelrc文件 ...
- vue.js+element ui Table+spring boot增删改查
小白初学,不懂的还是太多了,找了好多资料才做出来的先记录一下 1.先用Spring boot创建一个包含了增删改查的项目 2.创建vue.js项目 3.安装Element UI (1)进入项目文件夹下 ...
- vue开源Element UI表单设计及代码生成器
在日常的开发工作中,表单开发是较为繁琐且重复的.本文介绍一个我自己写的,提高开发效率的小工具. 1 可视化设计器 设计器基于Element UI ,可通过点击或拖拽的方式设计基本表单, 设计器生成的代 ...
- 基于Vue的前端UI组件库的比对和选型
大家好,我是张飞洪,感谢您的阅读,我会不定期和你分享学习心得,希望我的文章能成为你成长路上的垫脚石,让我们一起精进. 由于录制视频的需要,要做前端UI组件库的选型.平时国内外也见了不少基于Vue的UI ...
- Vue框架Element UI教程-axios请求数据
Element UI手册:https://cloud.tencent.com/developer/doc/1270 中文文档:http://element-cn.eleme.io/#/zh-CN gi ...
随机推荐
- 动态规划刷题集python代码
1 爬楼梯(Fibonacci) #有一楼梯共M级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? def fun(m): c = [0]*m c[0] = 1 c[1] = 2 for i ...
- Final发布点评
1. 约跑App——nice!:为改进演示效果,本组使用摄像头实时采集投影的方式展示其作品,是一种演示的创新.本组重点放在了修改上次来着其他组发现的bug,不过新功能上好像没有加入多少,可能是保证软 ...
- Postgresql迁移数据文件存放位置
1. POSTGRESQL的安装 centos7 里面默认的pgsql的版本是 如果想用更高的版本需要执行以下如下的命令 rpm -ivh https://download.postgresql.or ...
- FileReader & Blob & File
FileReader & Blob & File https://developer.mozilla.org/en-US/docs/Web/API/FileReader https:/ ...
- MT【105】待定系数算最大最小
已知$x,y,z>0$,则$max\{2x,\frac{1}{y},y+\frac{1}{x}\}$的最小值______ 分析:首先关注到$2x=\frac{1}{y}=y+\frac{1}{x ...
- Mac 显示sudo: pip: command not found
Mac显示sudo: pip: command not found mac在安装完pip模块后,使用pip命令会提示sudo: pip: command not found moyanzhudeMac ...
- python爬虫requests过程中添加headers
浏览器中打开页面,以edge为例,点击“查看源”或F12 第一步:点击上图中“网络”标签,然后刷新或载入页面 第二步:在右侧“标头”下方的“请求标头”中的所有信息都是headers内容,添加到requ ...
- Java 调用 groovy 脚本文件,groovy 访问 MongoDB
groovy 访问 MongoDB 示例: shell.groovy package db import com.gmongo.GMongoClient import com.mongodb.Basi ...
- bzoj千题计划291:bzoj3640: JC的小苹果
http://www.lydsy.com/JudgeOnline/problem.php?id=3640 dp[i][j] 表示i滴血到达j的概率 dp[i][j] = Σ dp[i+val[i]][ ...
- FFprobe使用指南
http://blog.csdn.net/stone_wzf/article/details/45378759 http://blog.chinaunix.net/uid-26000296-id-42 ...