Rubaxa-Sortable无法在'Element'上执行'matches':'>*'不是有效的选择器

Cod*_*mer 4 javascript drag-and-drop vue.js rubaxa-sortable vuejs2

我正在使用vuejs和Rubaxa Sortable JavaScript库.可排序工作正常,<ul><li>但是对于表行,当我通过拖放重新排列时,它会出现此错误.

Sortable.min.js:3 Uncaught DOMException: Failed to execute 'matches' on 'Element': '>*' is not a valid selector.
Run Code Online (Sandbox Code Playgroud)

我正在使用Vue.js v2.5.13和Rubaxa Sortable v1.7.0.

Vue.directive('sortable', {
  inserted: function (el, binding) {
    var sortable = new Sortable(el, binding.value || {});
  }
});
new Vue({
  el: '#app',
  data () {
    return {
      items: [{id: 1},{id: 2},{id: 3},{id: 4},{id: 5}]
    }
  },
  methods: {
    reorder ({oldIndex, newIndex}) {
      const movedItem = this.items.splice(oldIndex, 1)[0]
      this.items.splice(newIndex, 0, movedItem)
    }
  }
})
Run Code Online (Sandbox Code Playgroud)
<script src="https://vuejs.org/js/vue.min.js"></script>
<script src="https://cdn.rawgit.com/RubaXa/Sortable/c35043730c22ec173bac595346eb173851aece20/Sortable.min.js"></script>
<div id="app">
  <h2>With List</h2>
  <ul v-sortable="{onEnd: reorder}">
    <li v-for="i in items" :key="i.id">{{ i.id }}</li>
  </ul>

  <hr/>

  <h2>With Table</h2>
  <table v-sortable="{onEnd: reorder}">
    <tr v-for="i in items" :key="i.id">
      <td>{{ i.id }}</td>
    </tr>
  </table>

  {{ items }}

</div>
Run Code Online (Sandbox Code Playgroud)

Mun*_*nna 5

A <table>不能包含表行(<tr>).表的结构是这样的.

<table>
   <thead></thead>
   <tbody></tbody>
   <tfoot></tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)

所以当我们写这样的html表时,

<table>
   <tr>First Row</tr>
   <tr>Second Row</tr>
</table>
Run Code Online (Sandbox Code Playgroud)

浏览器会自动在里面插入所有行<tbody>并像这样呈现它.

<table>
   <tbody>
      <tr>First Row</tr>
      <tr>Second Row</tr>
   </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

所以表行不是直接的子代<table>,而是它们的子代<tbody>.因此,在里面生成表行<tbody>并添加v-sortable <tbody>.

<table>
   <tbody v-sortable="{onEnd: reorder}">  <!-- v-sortable here -->
      <tr v-for="i in items" :key="i.id">
         <td>{{ i.id }}</td>
      </tr>
   </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

Sortable的缩小版本有一个bug,当它们被try-catch缩小时会以某种方式摆脱一个块,导致它在<ul><li>排序以外的任何事情时失败.因此,直到他们修复它,使用开发即未压缩的Sortable版本.