vue中handsontable 使用
handsontable是目前在前端界最接近excel的插件,可以执行编辑,复制粘贴,插入删除行列,排序等复杂操作
1.安装模块包
npm install handsontable-pro @handsontable-pro/vue
npm install handsontable @handsontable/vue
这样安装完handsontable依赖的各模块(moment、numbro、pikaday 、zeroclipboard)也一起安装完了,不必再单独安装
2.引入模块包
import { HotTable } from '@handsontable-pro/vue'
import '../../node_modules/handsontable-pro/dist/handsontable.full.css'
import Handsontable from 'handsontable-pro'
代码示例
<template>
<div id="hot-preview">
<HotTable :root="root" ref="testHot" :settings="hotSettings"></HotTable>
</div>
</template> <script>
import { HotTable } from '@handsontable-pro/vue'
import '../../node_modules/handsontable-pro/dist/handsontable.full.css'
import Handsontable from 'handsontable-pro' export default {
data: function() {
return {
root: 'test-hot',
hotSettings: {
// data: [['sample', 'data']],
data: [ //数据可以是二维数组,也可以是数组对象 [false,'20080101', 10, 11, 12, 13,true], [false,'20090101', 20, 11, 14, 13,true], [false,'20010101', 30, 15, 12, 13,true], [false,'20010101', 32, 213, 21, 312,true], [false,'20010201', 32, 213, 21, 312,true], [false,'20010301', 32, 213, 21, 312,true], [false,'20010401', 32, 213, 21, 312,true], [false,'20010501', 32, 213, 21, 312,true], [false,'20010601', 32, 213, 21, 312,true] ],
// colHeaders: true,
startRows: 11,//行列范围 startCols: 6, minRows: 5, //最小行列 minCols: 5, maxRows: 20, //最大行列 maxCols: 20,
rowHeaders: true,//行表头,可以使布尔值(行序号),可以使字符串(左侧行表头相同显示内容,可以解析html),也可以是数组(左侧行表头单独显示内容)。 colHeaders: [ '选择','题目', 'A选项', 'B选项', 'C选项', 'D选项','答案',],//自定义列表头or 布尔值
minSpareCols: 2, //列留白 minSpareRows: 2,//行留白
// currentRowClassName: 'currentRow', //为选中行添加类名,可以更改样式
// currentColClassName: 'currentCol',//为选中列添加类名
autoWrapRow: true, //自动换行
contextMenu:{
items:{
"row_above": {
name:'上方插入一行'
},
"row_below": {
name:'下方插入一行'
},
"col_left": {
name:'左方插入列'
},
"col_right": {
name:'右方插入列'
},
"hsep1": "---------", //提供分隔线
"remove_row": {
name: '删除行',
},
"remove_col": {
name: '删除列',
},
"make_read_only": {
name: '只读',
},
"borders":{
name:'表格线'
},
"copy":{
name:'复制'
},
"cut":{
name:'剪切'
},
"commentsAddEdit": {
name: '添加备注',
},
"commentsRemove": {
name: '取消备注',
},
"freeze_column": {
name: '固定列',
},
"unfreeze_column": {
name: '取消列固定',
},
"hsep2": "---------",
}
},
manualColumnFreeze: true, //手动固定列 ?
manualColumnMove: true, //手动移动列
manualRowMove: true, //手动移动行
manualColumnResize: true,//手工更改列距
manualRowResize: true,//手动更改行距
comments: true, //添加注释 ?
cell: [ //???
{row: 1, col: 1, comment: {value: 'this is test'}},
],
customBorders:[],//添加边框
columnSorting: true,//排序
stretchH: 'all',//根据宽度横向扩展,last:只扩展最后一列,none:默认不扩展
fillHandle: true, //选中拖拽复制 possible values: true, false, "horizontal", "vertical"
fixedColumnsLeft: 2,//固定左边列数
fixedRowsTop: 2,//固定上边列数
mergeCells: [ //合并
// {row: 1, col: 1, rowspan: 3, colspan: 3}, //指定合并,从(1,1)开始行3列3合并成一格
// {row: 3, col: 4, rowspan: 2, colspan: 2}
],
columns: [ //添加每一列的数据类型和一些配置
{type: 'checkbox'}, //多选框
{
type: 'date', //时间格式
dateFormat: 'YYYY-MM-DD',
correctFormat: true,
defaultDate: '19000101'
},
{
type: 'dropdown', //下拉选择
source: ['BMW', 'Chrysler', 'Nissan', 'Suzuki', 'Toyota', 'Volvo'],
strict: false //是否严格匹配
},
{type: 'numeric'}, //数值
{type: 'numeric',
readOnly: true //设置只读
},
{ type: 'numeric',
format: '$ 0,0.00'}, //指定的数据格式
{}, ],
}
};
},
methods:{
testFunc:function(){
//this.$refs.hotTable.table就是当前的表格的对象
console.log(this.$refs.hotTable.table)
}
},
components: {
HotTable
}
}
</script>
vue中handsontable 使用的更多相关文章
- 在vue中使用handsontable
1.使用npm安装 npm install handsontable @handsontable/vue 2.定义结构 <hot-table :settings="hotSetting ...
- vue中如何不通过路由直接获取url中的参数
前言:为什么要不通过路由直接获取url中的参数? vue中使用路由的方式设置url参数,但是这种方式必须要在路径中附带参数,而且这个参数是需要在vue的路由中提前设置好的. 相对来说,在某些情况下直接 ...
- vue中的重要特性
一.vue中的自定义组件 html的代码: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- Vue中comoputed中的数据绑定
Vue中的数据实现响应式绑定是在初始化的时候利用definePrototype的定义set和get过滤器,在进行组件模板编译时实现water的监听搜集依赖项,当数据发生变化时在set中通过调用dep. ...
- vue中使用stompjs实现mqtt消息推送通知
最近在研究vue+webAPI进行前后端分离,在一些如前端定时循环请求后台接口判断状态等应用场景用使用mqtt进行主动的消息推送能够很大程度的减小服务端接口的压力,提高系统的效率,而且可以利用mqtt ...
- Vue中应用CORS实现AJAX跨域,及它在 form data 和 request payload 的小坑处理
基本概念部分(一):理解CORS 说道Vue的跨域AJAX,我想先梳理一遍CORS跨域,"跨域资源共享"(Cross-origin resource sharing),它是一个W3 ...
- vue中watched属性
watched属性,vue中的观察属性,可用来监听一个值的变化 默认有两个参数,新值,旧值 data (){ return { currentCity: "深圳" } } watc ...
- 七、vue中v-for有时候对页面不会重新渲染,数组变化后如何到渲染页面
v-for不能进行双向数据绑定,页面渲染完成后,再次更改v-for遍历的数据,js里面打印的数据看到数据值已经更改,但是页面的数据就是没有渲染,这是为什么呢? vue中v-for和angularj ...
- 【Vue】Vue中的父子组件通讯以及使用sync同步父子组件数据
前言: 之前写过一篇文章<在不同场景下Vue组件间的数据交流>,但现在来看,其中关于“父子组件通信”的介绍仍有诸多缺漏或者不当之处, 正好这几天学习了关于用sync修饰符做父子组件数据双向 ...
随机推荐
- Unicode类别
Unicode 通用类别: http://msdn.microsoft.com/zh-cn/library/20bw873z(VS.80).aspx 类别 说明 Lu 字母,大写 Ll 字母,小写 L ...
- spring aop expression支持多个表达式配置
<!-- 配置那些类的方法进行事务管理 --> <aop:config> <aop:pointcut id="allServiceMethod" ex ...
- How is javascript asynchronous AND single threaded?
原文: https://www.sohamkamani.com/blog/2016/03/14/wrapping-your-head-around-async-programming/ ------- ...
- 【共享单车】—— React后台管理系统开发手记:权限设置和菜单调整(未完)
前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...
- 清理memcached缓存
清理memcached缓存 学习了:https://blog.csdn.net/allus0918/article/details/50481927 使用telnet登录 flush_all 命令:
- Gentoo:startx出现Failed to load module问题
安装完xorg-server后,startx启动桌面环境,出现缺少模块错误. 查看log: cat /var/log/Xorg.0.log | grep EE [75.403] (EE) Failed ...
- iOS uitableivewCell 下划线顶格
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath ...
- RabbitMQ一
RabbitMQ: 一.rabbitmq的系统架构: RabbitMQ Server:也叫broker server,它不是运送食物的卡车,而是一种传输服务.原话是RabbitMQisn’t a fo ...
- POJ2536 Gopher II【二分图最大匹配】
题目链接: http://poj.org/problem? id=2536 题目大意: 有N仅仅鼹鼠和M个洞穴,假设鼹鼠在S秒内不可以跑到洞穴,就会被老鹰捉住吃掉. 鼹鼠跑的速度为V米/秒. 已知一个 ...
- zabbix web monitoring 监控网页
配置 Web 场景 配置 web 场景: 转到: 配置 (Configuration)–>主机 (或者 模板 ) 点击主机 (host)/ 模板 (template) 行中的 Web 点击右上角 ...