0

我正在尝试实现 vue 可拖动,它几乎似乎可以工作,除非我尝试在按钮上实现它。每当我尝试移动按钮时,它都会给我一条错误消息。

这是一个例子:https ://codepen.io/anon/pen/xoQRMV?editors=1111

          <div id="app">
    <v-app id="inspire">
      <v-container>
        <v-layout justify-center>
     <v-flex>
       <draggable v-model="myArray" :options="options" handle=".handle">    
          <div v-for="element in myArray" :key="element.id" class="title 
        mb-3">{{element.name}}
             <v-icon color="red" class="handle mt-0">drag_handle</v-icon>
           </div>   
          <v-btn class="ml-0">Button</v-btn>
          <v-icon color="red" class="handle">drag_handle</v-icon>
         </draggable>
        </v-flex>
       </v-layout>
   </v-container>
     </v-app>
   </div>


        new Vue({
    el: '#app',
     data() {
     return {
      myArray: [
       {name: 'Text1!!!!', id: 0},
       {name: 'Text2!!!!', id: 1},
         ],
         options: {
        handle: '.handle'
        }
            }
           }
          })

任何帮助表示赞赏。

4

2 回答 2

2

我认为它必须从单个数组中工作,例如 https://codepen.io/anon/pen/agQVvm?editors=1111

<div id="app">
  <v-app id="inspire">
     <v-container>
       <v-layout justify-center>
         <v-flex>
           <draggable :list="combinedArray" :options="options" handle=".handle">    
             <div v-for="element in combinedArray" :key="element.id" class="title mb-3">
               <div v-if="element.type !== 'button'" class="title mb-3">
                 {{ element.name }}
                 <v-icon color="red" class="handle mt-0">drag_handle</v-icon>
               </div>

               <div v-else>
                 <v-btn>{{ element.name }}</v-btn>
                 <v-icon color="red" class="handle mt-0">drag_handle</v-icon>
               </div>
             </div>  
           </draggable>
         </v-flex>
       </v-layout>
  </v-container>
  </v-app>
</div>

new Vue({
  el: '#app',

  created () {
    this.combinedArray = [...this.myArray, ...this.buttonsArray]
  },

  data () {
    return {
      myArray: [
        { name: 'Text1!!!!', id: 0 },
        { name: 'Text2!!!!', id: 1 }
      ],
      buttonsArray: [
        { name: 'Button1', id: 2, type: 'button' },
        { name: 'Button2', id: 3, type: 'button' }
      ],
      combinedArray: [],
      options: {
        handle: '.handle'
      }
    }
  }
})
于 2019-07-08T22:23:13.140 回答
0

我能够通过创建自己的数组来实现按钮的拖动:-

   <draggable class="list-group"  :list="buttonArray" :options="options" 
       handle=".handle" group="drags">
         <div v-for="item in buttonArray" :key="item.id">
          <v-btn class="ml-0">{{item.name}}</v-btn>
          <v-icon color="red" class="handle">drag_handle</v-icon>
           </div>
         </draggable>

             buttonArray: [
       {name: 'Button1', id: 2},
       {name:'Button2', id:3}
         ],

更新的笔:- https://codepen.io/anon/pen/xoQRMV?editors=1111

但是,它会产生一个问题,即我无法用按钮替换文本。:(

于 2019-07-08T21:40:01.310 回答