vue 拖拽排序

3 篇文章 0 订阅
2 篇文章 0 订阅
<template>

  <div>

    <transition-group tag="div" class="container">

      <div

        class="item"

        v-for="(item,index) in items"

        :key="item.key"

        :style="{background:item.color,width:'80px',height:'80px'}"

        draggable="true"

        @dragstart="handleDragStart($event, item)"

        @dragover.prevent="handleDragOver($event, item)"

        @dragenter="handleDragEnter($event, item)"

        @dragend="handleDragEnd($event, item)"

      ></div>

    </transition-group>

  </div>

</template>



<script>

export default {

  name: "pzoomFormPlaceBid",

  props: {

    value: Object,

  },

  data() {

    return {

      items: [

        { key: 1, color: "#ffebcc" },

        { key: 2, color: "#ffb86c" },

        { key: 3, color: "#f01b2d" },

      ],

      dragging: null,

      dataList: [],

      siteMap: [

        {

          key: "SITE_SET_KANDIAN",

          name: "腾讯看点",

          parent: "tx",

          bid: null,

        },

        {

          key: "SITE_SET_QQ_MUSIC_GAME",

          name: "QQ、腾讯音乐及游戏",

          parent: "tx",

          bid: null,

        },

        {

          key: "SITE_SET_TENCENT_NEWS",

          name: "腾讯新闻",

          parent: "tx",

          bid: null,

        },

        {

          key: "SITE_SET_TENCENT_VIDEO",

          name: "腾讯视频",

          parent: "tx",

          bid: null,

        },

        {

          key: "SITE_SET_MOBILE_UNION",

          name: "优量汇",

          parent: "ylh",

          bid: null,

        },

      ],

      // bid_adjustment: {

      //   site_set_package: [

      //     {

      //         site_set: [

      //             "SITE_SET_QZONE"

      //         ],

      //         bid_coefficient: 1

      //     },

      //     {

      //         site_set: [

      //             "SITE_SET_QZONE",

      //             "SITE_SET_QZONE",

      //         ],

      //         bid_coefficient: 2

      //     }

      //   ]

      // }

    };

  },

  watch: {

    "value.site_set": {

      handler(val) {

        if (this.$store.createWatchLock) {

          return false;

        }

        if (val.length > 0) {

          if (val.includes("SITE_SET_MOBILE_UNION")) {

          }

        }

      },

      immediate: false,

    },

  },

  methods: {

    handleDragStart(e, item) {

      this.dragging = item;

    },

    handleDragEnd(e, item) {

      this.dragging = null;

    },

    //首先把div变成可以放置的元素,即重写dragenter/dragover

    handleDragOver(e) {

      console.log("handleDragOver");

      e.dataTransfer.dropEffect = "move"; // e.dataTransfer.dropEffect="move";//在dragenter中针对放置目标来设置!

    },

    handleDragEnter(e, item) {

      e.dataTransfer.effectAllowed = "move"; //为需要移动的元素设置dragstart事件

      if (item === this.dragging) {

        return;

      }

      const newItems = [...this.items];

      console.log(newItems);

      const src = newItems.indexOf(this.dragging);

      const dst = newItems.indexOf(item);



      newItems.splice(dst, 0, ...newItems.splice(src, 1));



      this.items = newItems;

    },

  },

};

</script>



<style lang="scss" scoped>

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值