首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vuejs可排序改变颜色的拖动?

vuejs可排序改变颜色的拖动?
EN

Stack Overflow用户
提问于 2019-06-21 00:08:06
回答 1查看 477关注 0票数 0

我正在尝试使用sortable实现Vue拖放,到目前为止,它似乎还在工作,但是当拖动开始时,我如何才能改变元素的颜色呢?

表元素外的按钮是其颜色应该改变的按钮。

下面是一个有效的代码:https://codepen.io/anon/pen/pXRWeP

代码语言:javascript
复制
  <v-container>
      <v-data-table :headers="headers" :items="desserts" hide-actions 
   class="elevation-2">
        <template slot="items" slot-scope="props">
       <td >
        <v-btn class="handle" style="max-width: 28px;">
        <v-icon>drag_handle</v-icon>
        </v-btn></td>
      <td>{{ props.item.name }}</td>
      <td class="text-xs-right">{{ props.item.calories }}</td>
      <td class="text-xs-right">{{ props.item.fat }}</td>
      <td class="text-xs-right">{{ props.item.carbs }}</td>
      <td class="text-xs-right">{{ props.item.protein }}</td>
      <td class="text-xs-right">{{ props.item.iron }}</td>
    </template>
      </v-data-table>
    <v-btn>Change color of this button when dragging starts</v-btn>
  </v-container>


     new Vue({
   el: '#app',
  data: () => ({
    headers: [
    {
      text: "",
      align: "left",
      sortable: false
    },
    {
      text: "Dessert (100g serving)",
      align: "left",
      sortable: false,
      value: "name"
    },
    { text: "Calories", value: "calories" },
    { text: "Fat (g)", value: "fat" },
    { text: "Carbs (g)", value: "carbs" },
    { text: "Protein (g)", value: "protein" },
    { text: "Iron (%)", value: "iron" }
  ],
  desserts: [
    {
      value: false,
      name: "Lollipop",
      calories: 159,
      fat: 6.0,
      carbs: 24,
      protein: 4.0,
      iron: "1%"
    },
    {
      value: false,
      name: "Marshamallow",
      calories: 262,
      fat: 16.0,
      carbs: 23,
      protein: 6.0,
      iron: "7%"
    },
    {
      value: false,
      name: "Noughat",
      calories: 305,
      fat: 3.7,
      carbs: 67,
      protein: 4.3,
      iron: "8%"
    },
    {
      value: false,
      name: "Oreo",
      calories: 356,
      fat: 16.0,
      carbs: 49,
      protein: 3.9,
      iron: "16%"
    },
  ]
 }),
  mounted() {
   let table = document.querySelector(".v-datatable tbody");
   const _self = this;
   Sortable.create(table, {
     handle: ".handle",
      onEnd({ newIndex, oldIndex }) {
      const rowSelected = _self.desserts.splice(oldIndex, 1)[0]; 
      _self.desserts.splice(newIndex, 0, rowSelected); 
     }
   });
  }
 })

先谢谢你们了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-21 01:12:24

您已经在Sortable.create调用中为onEnd定义了一个函数。为onStart添加一个。在data中添加一个color键,并将按钮的颜色绑定到它。在onStart调用中,将_self.color设置为新颜色;在onEnd中,将其设置回旧颜色。

我用结果修改了你的codepen:https://codepen.io/djsmedes/pen/WqRdxm

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

https://stackoverflow.com/questions/56689991

复制
相关文章

相似问题

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