在vue中使用了表格组件handsontable的vue版本vue-handsontable-official,但是大多数时候都会使用到原始版本的一些方法,但是在原始版本中会创建handsontable对象,通过对象调用方法,但是在vue版本中,handsontable是作为一个组件的,没有创建它的对象,这时候我应该怎么调用它本身的方法呢?原始版本的使用示例:hot = Handsontable(document.getElementById('example1'), { data: data, minRows: 5, minCols: 6, currentRowClassName: 'currentRow', currentColClassName: 'currentCol', rowHeaders: true, colHeaders: true, selectCell:selectCell1 }); hot.selectCell(1,2,3,4);vue的使用示例:<template> <div id="hot-preview"> <HotTable :root="root" :settings="hotSettings"></HotTable> </div></template><script> import HotTable from 'vue-handsontable-official'; export default { data: function() { return { root: 'test-hot', hotSettings: { data: [['sample', 'data']], colHeaders: true } }; }, components: { HotTable } }</script>上面的例子是在原始版本中调用它本身的一个方法,选中指定的单元格。但是我想在vue中使用这个方法,不知道怎么才能调用,麻烦研究过这块的同学帮忙解答一下,不甚感激!
1 回答

牧羊人nacy
TA贡献1862条经验 获得超7个赞
我找到了一个方法,可以使用vue的ref属性绑定对象。
示例:
<template>
<div id="hot-preview">
<HotTable :root="root" ref="testHot" :settings="hotSettings"></HotTable>
</div>
</template>
<script>
import HotTable from 'vue-handsontable-official';
export default {
data: function() {
return {
root: 'test-hot',
hotSettings: {
data: [['sample', 'data']],
colHeaders: true
}
};
},
methods:{
testFunc:function(){
//this.$refs.hotTable.table就是当前的表格的对象
console.log(this.$refs.hotTable.table)
}
}
components: {
HotTable
}
}
</script>
添加回答
举报
0/150
提交
取消