VueJS拖放[需要简单的CSS修复]

时间:2019-02-11 16:35:26

标签: jquery css css3 vue.js vuejs2

我正在开发一个基于VueJS的项目,需要一个拖放+可嵌套选项,如下文所示。到目前为止,我们取得了很多成就,但是,我仍然无法弄清楚为什么递归函数不能很好地发挥作用。

有人可以帮我弄清楚吗? JSFiddle也位于底部。

更新:我只是弄清楚,这只是一个 CSS 问题。那么有什么CSS专家可以帮助我吗?

var local = {
  template: '#template-drag',
  name: 'local-draggable',
  props: ['tasks']
};


new Vue({
  el: "#app",
    components: {
        "local-draggable" : local
  },
  data: {
  "tasks": [
    {
      "name": "task 1",
       "tasks": []
    },
    {
      "name": "task 2",
       "tasks": []
    },{
      "name": "task 3",
       "tasks": []
    },
    {
      "name": "task 4",
       "tasks": []
    },
    {
      "name": "task 5",
       "tasks": []
    },
    {
      "name": "task 6",
       "tasks": [
        {
          "name": "task 6.1",
           "tasks": []
        }
       ]
    }
  ]
  },
});
.parent{
  position: relative;
  padding-left: 15px;
}

.dragArea {
  border: 1px dashed;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.dragArea .dragArea > .parent {
  position: relative;
  padding-top: 23px;
  padding-left: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/sortablejs@1.7.0"></script>
<script src="https://unpkg.com/vuedraggable@2.16.0/dist/vuedraggable.js"></script>


<script type="text/x-template" id="template-drag">
   <draggable :element="'div'" :list="tasks" class="dragArea" :options="{group:{ name:'g1'}}" > 
		<template v-for="el in tasks" class="parent">
			<div class="parent">
				<p>{{el.name}} - {{el.tasks}}</p>
				<local-draggable :tasks="el.tasks"/>
			</div>
		</template>
	</draggable>
</script>


<div id="app">       
  <local-draggable :tasks="tasks"/>
</div>


如果是,我附上了JSFiddle:https://jsfiddle.net/minuwan/nb15jd48/

1 个答案:

答案 0 :(得分:0)

您可以这样做。

var local = {
  template: '#template-drag',
  name: 'local-draggable',
  props: ['tasks']
};


new Vue({
  el: "#app",
    components: {
        "local-draggable" : local
  },
  data: {
  "tasks": [
    {
      "name": "task 1",
       "tasks": []
    },
    {
      "name": "task 2",
       "tasks": []
    },{
      "name": "task 3",
       "tasks": []
    },
    {
      "name": "task 4",
       "tasks": []
    },
    {
      "name": "task 5",
       "tasks": []
    },
    {
      "name": "task 6",
       "tasks": [
        {
          "name": "task 6.1",
           "tasks": []
        }
       ]
    }
  ]
  },
});
.parent{
  position: relative;
  padding-left: 15px;
}

.dragArea {
  border: 1px dashed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.dragArea .dragArea > .parent {
  position: relative;
  padding-left: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/sortablejs@1.7.0"></script>
<script src="https://unpkg.com/vuedraggable@2.16.0/dist/vuedraggable.js"></script>


<script type="text/x-template" id="template-drag">
   <draggable :element="'div'" :list="tasks" class="dragArea" :options="{group:{ name:'g1'}}" > 
		<template v-for="el in tasks" class="parent">
			<div class="parent">
				<p>{{el.name}} - {{el.tasks}}</p>
				<local-draggable :tasks="el.tasks"/>
			</div>
		</template>
	</draggable>
</script>


<div id="app">       
  <local-draggable :tasks="tasks"/>
</div>