我在Vue.js有一张用Vue-good桌子做的桌子.
我需要找到一种可以调整大小的方法。就像这样。https://codepen.io/validide/pen/aOKLNo
不幸的是,据我所知,Vue-好桌子没有这个选择。https://github.com/xaksis/vue-good-table/issues/226
我用JQuery进行了测试,但我不想将Jquery和Vue混合起来,我也不知道Jquery中的库是否与这个组件一起工作。我做了测试,但没有找到。
在Javascript/css或Vue中还有另一种方法可以实现吗?
<vue-good-table
@on-select-all="'selectAll'"
:columns="columns"
:rows="rows"
:select-options="{ enabled: true }"
@on-selected-rows-change="selectionChanged"
:sort-options="{
enabled: true
}"></<vue-good-table>谢谢。
发布于 2019-10-08 07:04:37
将mounted方法添加到组件中,如下所示:
mounted: function () {
var thElm;
var startOffset;
Array.prototype.forEach.call(
document.querySelectorAll("table th"),
function (th) {
th.style.position = 'relative';
var grip = document.createElement('div');
grip.innerHTML = " ";
grip.style.top = 0;
grip.style.right = 0;
grip.style.bottom = 0;
grip.style.width = '5px';
grip.style.position = 'absolute';
grip.style.cursor = 'col-resize';
grip.addEventListener('mousedown', function (e) {
thElm = th;
startOffset = th.offsetWidth - e.pageX;
});
th.appendChild(grip);
});
document.addEventListener('mousemove', function (e) {
if (thElm) {
thElm.style.width = startOffset + e.pageX + 'px';
}
});
document.addEventListener('mouseup', function () {
thElm = undefined;
});
}发布于 2018-10-11 11:44:33
为什么不用自己的香草JavaScript解决方案创建一个无渲染包装组件呢?就像这样:
http://jsfiddle.net/thrilleratplay/epcybL4v/
(function () {
var thElm;
var startOffset;
Array.prototype.forEach.call(
document.querySelectorAll("table th"),
function (th) {
th.style.position = 'relative';
var grip = document.createElement('div');
grip.innerHTML = " ";
grip.style.top = 0;
grip.style.right = 0;
grip.style.bottom = 0;
grip.style.width = '5px';
grip.style.position = 'absolute';
grip.style.cursor = 'col-resize';
grip.addEventListener('mousedown', function (e) {
thElm = th;
startOffset = th.offsetWidth - e.pageX;
});
th.appendChild(grip);
});
document.addEventListener('mousemove', function (e) {
if (thElm) {
thElm.style.width = startOffset + e.pageX + 'px';
}
});
document.addEventListener('mouseup', function () {
thElm = undefined;
});
})();没有必要使用jQuery。您可以使用自定义无渲染组件包装您的表,并使用this.$el和document.querySelector深入到其槽组件中。
发布于 2018-10-11 11:54:22
您可以在vanillajs https://github.com/MonsantoCo/column-resizer中尝试这个库。
<div id="app">
<table border="1" ref="table">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</tbody>
</table>
</div>
<script>
new Vue({
el: "#app",
data: {},
mounted() {
let resizable = ColumnResizer.default
new resizable(this.$refs.table, {
liveDrag:true,
draggingClass:"rangeDrag",
gripInnerHtml:"<div class='rangeGrip'></div>",
minWidth:8
})
}
})
</script>https://stackoverflow.com/questions/52759087
复制相似问题