首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可调整尺寸的Vue -好表或Vue

可调整尺寸的Vue -好表或Vue
EN

Stack Overflow用户
提问于 2018-10-11 11:35:41
回答 3查看 9K关注 0票数 8

我在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中还有另一种方法可以实现吗?

代码语言:javascript
复制
<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>

谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-10-08 07:04:37

mounted方法添加到组件中,如下所示:

代码语言:javascript
复制
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 = "&nbsp;";
        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;
    });
}
票数 5
EN

Stack Overflow用户

发布于 2018-10-11 11:44:33

为什么不用自己的香草JavaScript解决方案创建一个无渲染包装组件呢?就像这样:

http://jsfiddle.net/thrilleratplay/epcybL4v/

代码语言:javascript
复制
(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 = "&nbsp;";
        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.$eldocument.querySelector深入到其槽组件中。

票数 5
EN

Stack Overflow用户

发布于 2018-10-11 11:54:22

您可以在vanillajs https://github.com/MonsantoCo/column-resizer中尝试这个库。

代码语言:javascript
复制
<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://jsfiddle.net/Wagner/eywraw8t/414137/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52759087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档