美文网首页
vue vuedraggable 拖拽组件

vue vuedraggable 拖拽组件

作者: 奕格 | 来源:发表于2021-12-10 14:10 被阅读0次

    安装插件

    yarn add vuedraggable

    <template>

        <draggable v-model="dataList" @update="draggableEnd">

            <transition-group class="display-flex flex-wrap-wrap">

                <div v-for="itemin dataList" :key="item" class="item-class">

                    <div v-text="item"></div>

                </div>

            </transition-group>

        </draggable>

    </template>

    <script>

    import draggable from 'vuedraggable';

    export default{

      name: 'ClassMeeting',

      components: {draggable},

      props: {},

      data() {

        return{

          dataList: ['张三','李四','王武','张怡宁','刘诗雯']

        }

      },

      methods: {

        draggableEnd(e) {

          console.log("拖动前的索引 :" + e.oldIndex);

          console.log("拖动后的索引 :" + e.newIndex);

        },

      }

    }

    </script>

    .item-class{

      width: 300px;

      height: 50px;

      line-height: 50px;

      background-color: #0077aa;

      color: #ffffff;

      margin-right: 5px;

      margin-top: 5px;

    }

    </style>

    相关文章

      网友评论

          本文标题:vue vuedraggable 拖拽组件

          本文链接:https://www.haomeiwen.com/subject/pjpcfrtx.html