使用vuedraggable實(shí)現(xiàn)從左向右拖拽功能
本文實(shí)例為大家分享了使用vuedraggable實(shí)現(xiàn)從左向右拖拽的具體代碼,供大家參考,具體內(nèi)容如下
1 功能描述
使用vuedraggable實(shí)現(xiàn)從左邊框中拖拽到右邊的框中,左邊的框不能隨意拖拽改變位置,不能向左邊框中拖拽組件。右邊框中的組件可以拖動(dòng)位置,但不能拖入到左邊框里。
注意事項(xiàng)如下:
(1)draggable的group中的name屬性必須一致;
(2)左邊框中的draggable必須含有以下屬性,group中的pull:'clone'屬性表示可以生成新的組件;group中的put:false屬性表示不能向里面拖拽組件;{sort: false}屬性表示不能更改組件的位置。
(3)左邊框中的draggable中的clone="cloneItem"表示組件被拖拽到右邊框中后,將生成的是新的組件,如果修改右邊組件的數(shù)據(jù)不會(huì)影響左邊組件的數(shù)據(jù)。cloneItem實(shí)現(xiàn)的是對(duì)每個(gè)組件的深復(fù)制。如果要實(shí)現(xiàn)修改兩邊框中的任何組件,兩邊組件都會(huì)同步變化,則需要?jiǎng)h除clone="cloneItem"屬性。
(4)右邊框中的draggable中的start屬性是監(jiān)聽開始拖動(dòng)組件,add是監(jiān)聽添加組件,可以根據(jù)情況調(diào)用其中的數(shù)據(jù)。
(5)從左邊框拖入右邊框中判斷單個(gè)數(shù)據(jù)是否合法,可以使用move屬性,如果,左側(cè)單個(gè)數(shù)據(jù)不合法返回false,則無法添加到右側(cè)框中。
2 截圖
3 源代碼
<template> ? <div class="my_draggle"> ? ? <div class="md_title">使用vuedraggable實(shí)現(xiàn)從左到右拖拽</div> ? ?? ? ? <div class="md_con"> ? ? ? <draggable ? ? ? ? class="mdc_left" ? ? ? ? v-model="originDataArr" ? ? ? ? v-bind="{sort: false}" ? ? ? ? v-bind:group="{ name:'person', pull:'clone', put:false }" ? ? ? ? v-bind:clone="cloneItem"> ? ? ? ? ? <div v-for="(item,index) in originDataArr" v-bind:key="index"> ? ? ? ? ? <span>{{item.name}}</span> ? ? ? ? ? <span>{{item.sex}}</span> ? ? ? ? </div> ? ? ? ? </draggable> ? ? ? ? <draggable ? ? ? ? class="mdc_right" ? ? ? ? v-model="newDataArr" ? ? ? ? v-bind:group="{name:'person'}" ? ? ? ? v-on:start="dragItem" ? ? ? ? v-on:add="addItem"> ? ? ? ? <div v-for="(item,index) in newDataArr" v-bind:key="index"> ? ? ? ? ? <span><img v-bind:src="item.icon" /></span> ? ? ? ? ? <span>{{item.name}}</span> ? ? ? ? ? <span>{{item.sex}}</span> ? ? ? ? </div> ? ? ? </draggable> ? ? </div> ? </div> </template> ? <script> ? import draggable from "vuedraggable" ? export default { ? name: 'MyDraggle', ? components:{ ? ? draggable ? }, ? props: { ? ? msg: String ? }, ? data: function(){ ? ? return{ ? ? ? originDataArr: new Array(), ? ? ? newDataArr: new Array() ? ? } ? }, ? ? mounted: function(){ ? ? this.initData(); ? }, ? ? methods: { ? ? initData: function(){ ? ? ? this.originDataArr = [ ? ? ? ? {name:"張三", age: 15, sex: "男", icon: require("@/assets/logo.png")}, ? ? ? ? {name:"李四", age: 15, sex: "男", icon: require("@/assets/logo.png")}, ? ? ? ? {name:"王五", age: 15, sex: "男", icon: require("@/assets/logo.png")}, ? ? ? ? {name:"小花", age: 15, sex: "女", icon: require("@/assets/logo.png")} ? ? ? ] ? ? }, ? ? ? cloneItem: function(val){ ? ? ? // 深復(fù)制一個(gè)節(jié)點(diǎn) ? ? ? return JSON.parse(JSON.stringify(val))? ? ? }, ? ? ? dragItem: function(widget){ ? ? ? console.log(widget); ? ? }, ? ? ? addItem: function(widget){ ? ? ? console.log(widget); ? ? } ? } } </script> ? <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> .my_draggle{ ? position: relative; } ? .md_title{ ? font-size: 24px; ? height: 60px; } ? .md_con>div{ ? width: 600px; ? height: 600px; ? display: inline-block; ? border: 1px solid #CCCCCC; ? border-radius: 10px; ? vertical-align: top; } ? .mdc_left>div{ ? height: 40px; ? line-height: 40px; ? margin-top: 6px; ? border: 1px solid #CCCCCC; ? cursor: move; ? margin: 10px 20px; } ? .mdc_left>div:hover{ ? box-shadow: 1px 2px 4px #CCCCCC; } ? .mdc_right>div{ ? height: 40px; ? line-height: 40px; ? margin-top: 6px; ? border: 1px solid #CCCCCC; ? cursor: move; ? margin: 10px 20px; } ? .mdc_right>div:hover{ ? box-shadow: 1px 2px 4px #CCCCCC; } ? .mdc_right>div>span{ ? display: inline-block; ? vertical-align: top; } ? .mdc_right>div>span>img{ ? height: 30px; } ? </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue3中使用vuedraggable拖拽實(shí)戰(zhàn)教程
- 使用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序
- vue使用vuedraggable實(shí)現(xiàn)嵌套多層拖拽排序功能
- vue拖拽組件vuedraggable使用說明詳解
- vue3使用vuedraggable實(shí)現(xiàn)拖拽功能
- vuedraggable實(shí)現(xiàn)拖拽功能
- vuedraggable+element ui實(shí)現(xiàn)頁面控件拖拽排序效果
- vue拖拽排序插件vuedraggable使用方法詳解
- vue使用vuedraggable插件實(shí)現(xiàn)拖拽效果
相關(guān)文章
vue + element-ui的分頁問題實(shí)現(xiàn)
這篇文章主要介紹了vue + element-ui的分頁問題實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12Vue proxyTable配置多個(gè)接口地址,解決跨域的問題
這篇文章主要介紹了Vue proxyTable配置多個(gè)接口地址,解決跨域的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09electron?dialog.showMessageBox的使用案例
Electron?Dialog?模塊提供了api來展示原生的系統(tǒng)對(duì)話框,本文主要介紹了electron?dialog.showMessageBox的使用案例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-08-08