• vuejs2.0运用原生js实现简单的拖拽元素功能


    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta charset="utf-8">
    <title></title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    
    <style>
    .select-item {
      background-color: #5bc0de;
      display: inline-block;
      text-align: center;
      border-radius: 3px;
      margin-right: 10px;
      cursor:pointer;
      padding: 6px 20px;
      color: #fff;
    }
     .cursored{
      cursor: default;
    }
    .project-content,.people-content {
        margin: 30px 50px;
    }
    .people-content {
        margin-top: 30px;
    }
    .drag-div {
        border: 1px solid #5bc0de;
        padding:10px;
        margin-bottom: 10px;
        width: 800px;
        cursor: pointer;
    }
    .select-project-item {
        display: inline-block;
        text-align: center;
        border-radius: 3px;
    }
    .drag-people-label{
      margin-bottom:0;
      padding-right:10px;
    }
    [v-cloak]{
        display:none;
    }
    </style>
    </head>
    <body>
    
    <div class='drag-content' id="dragCon" >
      <div class='project-content'>
        <div class='select-item' draggable='true' @dragstart='drag($event)' v-for="pjdt in projectdatas">{{pjdt.name}}</div>
      </div>
      <div class='people-content'>
        <div class='drag-div' v-for="ppdt in peopledata" @drop='drop($event)' @dragover='allowDrop($event)'>
          <div class='select-project-item'>
            <label class='drag-people-label'>{{ppdt.name}}:</label>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript" src="js/vue.min2.js"></script>
    <script type="text/javascript">
        var dom;
        var ss = new Vue({
            'el':'#dragCon',
            data:{
                projectdatas:[{
                    id:1,
                    name:'葡萄'
                  },{
                    id:2,
                    name:'芒果'
                  },{
                    id:3,
                    name:'木瓜'
                  },{
                    id:4,
                    name:'榴莲'
                  }],
    
    
                   peopledata:[{
                    id:1,
                    name:'小颖'
                  },{
                    id:2,
                    name:'hover'
                  },{
                    id:3,
                    name:'空巢青年三 '
                  },{
                    id:3,
                    name:'一丢丢'
                  }]
    
            },
            mounted:function(){
                this.$nextTick(function(){
                    
                })
            },
              watch:{
                projectdatas:{
                    handler:function(val,oldval){
    
                    },
                    deep:true
                },
                peopledata:{
                    handler:function(val,oldval){
    
                    },
                    deep:true
                }
            },
    
            methods: {
                drag:function(event){
                   dom = event.currentTarget
                },
                drop:function(event){
                  event.preventDefault();
                  event.target.appendChild(dom);
                },
                allowDrop:function(event){
                  event.preventDefault();
                }
              }
    
        });
    
    
    </script>
    </body>
    </html>

    实现效果:

  • 相关阅读:
    数据库SQL优化大总结之 百万级数据库优化方案
    2020春季学期第九周学习总结
    2020春季学期第八周学习总结
    《一线架构师实践指南》第三章Refined Architecture阶段学习总结
    2020春季学期第七周学习总结
    2020春季学期第六周学习总结
    《软件架构设计》阅读笔记三
    2020春季学期第四周学习总结
    数据分析练习-3.14进度
    《软件架构设计》阅读笔记二
  • 原文地址:https://www.cnblogs.com/moqiutao/p/6432392.html
Copyright © 2020-2023  润新知