vue使用event.dataTransfer實(shí)現(xiàn)A容器數(shù)據(jù)拖拽復(fù)制到B容器方式
更新時(shí)間:2026年02月10日 14:16:05 作者:扶蘇1002
這篇文章主要介紹了vue使用event.dataTransfer實(shí)現(xiàn)A容器數(shù)據(jù)拖拽復(fù)制到B容器方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
A容器代碼
- template
<div class="field-list">
<div
v-for="col in columns"
:key="col.columnName"
class="field-item"
draggable="true"
@dragstart="onDragStart($event, col, 'field')"
>
<i class="el-icon-document"></i>
<span class="field-name">{{ col.columnName }}</span>
<span class="field-comment">{{ col.columnComment }}</span>
</div>
</div>
- 方法
function onDragStart(event, item, type) {
event.dataTransfer.setData("type", type);
event.dataTransfer.setData("data", JSON.stringify(item));
}
B容器代碼
<div class="condition-drop" @dragover.prevent @drop="onDropCondition">
<div
v-for="(cond, idx) in form.whereConfig.conditions"
:key="idx"
class="condition-row"
>
<el-tag>{{ cond.field }}</el-tag>
</div>
</div>
- 方法
function onDropCondition(event) {
const type = event.dataTransfer.getData("type");
if (type !== "field") return;
const data = JSON.parse(event.dataTransfer.getData("data"));
const exists = form.whereConfig.conditions.find((c) => c.field === data.columnName);
if (!exists) {
form.whereConfig.conditions.push({
field: data.columnName,
});
}
}
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
elementui中使用el-tabs切換實(shí)時(shí)更新數(shù)據(jù)
這篇文章主要介紹了elementui中使用el-tabs切換實(shí)時(shí)更新數(shù)據(jù),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
關(guān)于Vue中echarts響應(yīng)式頁面變化resize()的用法介紹
Vue項(xiàng)目中開發(fā)數(shù)據(jù)大屏,使用echarts圖表根據(jù)不同尺寸的屏幕進(jìn)行適配,resize()可以調(diào)用echarts中內(nèi)置的resize函數(shù)進(jìn)行自適應(yīng)縮放,本文將給大家詳細(xì)介紹resize()的用法,需要的朋友可以參考下2023-06-06
Vue2.0實(shí)現(xiàn)1.0的搜索過濾器功能實(shí)例代碼
本篇文章主要介紹了Vue2.0實(shí)現(xiàn)1.0的搜索過濾器功能實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
vue.js給動(dòng)態(tài)綁定的radio列表做批量編輯的方法
下面小編就為大家分享一篇vue.js給動(dòng)態(tài)綁定的radio列表做批量編輯的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02
Vue2項(xiàng)目如何使用pdfjs-dist解析pdf
這篇文章主要為大家詳細(xì)介紹了Vue2項(xiàng)目如何使用pdfjs-dist解析pdf相關(guān),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-05-05
vuejs+element-ui+laravel5.4上傳文件的示例代碼
本篇文章主要介紹了vuejs+element-ui+laravel5.4上傳文件的示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08

