【发布时间】:2017-08-18 11:49:15
【问题描述】:
我正在与draggable and sortable with vueJS 合作,我正在努力完成一件事,基本上我有 2 个列表,第一个是包含一些部分的列表,例如(表格、段落 ...)第二个是构建块有了这个部分,但基本上我需要的流程是,将一个元素从 list1 拖到 list2,但不要添加元素这很重要,因为我需要先打开一个模式来设置将要添加的元素,然后将其添加到 futureIndex 中。
目前我有一个解决方案,我几乎可以做我需要的事情,我只需要了解如何取消添加元素而无需为拖动的预览而苦恼,我的意思是预览:
我想看看中间那个元素的加法。
所以我的第一个列表是这样做的:
<draggable v-model="sectionList" class="dragArea" @end="changeView()" :move="moveItem" :options="{group:{ name:'sections',pull:'clone',put:false }}">
<div v-for="(section, index) in sectionList" class="card card-color list-complete-item">
<div class="card-block">
<h4 class="card-title text-center">{{section.text}}</h4>
</div>
</div>
</draggable>
methods: {
addParagraph() {
this.$set(this.paragraph, 'key', this.key);
this.$set(this.paragraph, 'text', this.text);
this.$set(this.paragraph, 'fontSize', this.fontSize);
this.$store.commit("appendToDocument", this.paragraph)
},
changeView: function () {
this.$store.commit("changeCurrentView", this.sectionList[this.dragedIndex].component);
this.show();
},
show() {
this.$modal.show('modalSection');
},
hide() {
this.$modal.hide('modalSection');
},
currentIndex(evt) {
console.log(evt.draggedContext.index);
},
moveItem(evt) { // future index of the modal that will be draged
console.log(evt.draggedContext.futureIndex);
this.dragedIndex = evt.draggedContext.index;
}
},
第二个列表并不重要,只要我能理解这篇文章,如何在不添加的情况下移动项目并查看预览。我在最后添加了 return false,但是我看不到预览,也无法在同一个列表之间拖动元素。
有什么帮助吗?
【问题讨论】:
-
为什么不在放置时插入元素?您可以使用克隆道具用占位符值填充克隆的元素并在结束事件时打开模型?我想它会完成这项工作,使用 move 道具和 futureindex 可能会出现问题,因为 futureindex 值存在一些已知问题
-
我想要这个解决方案的朋友,如果你能用一个例子来详细说明一下:)
标签: javascript vue.js vuejs2 draggable jquery-ui-sortable