Vue custom instruction drag

<div class="divModule"  v-drag="getData" :id="element.id" v-for="(element,index) in tags" :key="index" style="width:200px;height:200px">
        <divModule  :id="index+1" :property="element" @moduleProperty="getModuleProperty">
        </divModule>
        <div class="bigAndSmall" :id="index+1" v-move="getData">
        </div>
      </div>

there is a v-drag custom instruction on the div of the outer layer that can be used for drag and drop, which has been implemented.

< H2 > the problem now is that you want to drag the small red block in the lower left corner to control the size of the big div. But when you drag the small red block, the big div will also move because of bubbles. Is there any way to solve it? Or there are other ideas to achieve this operation. Ask the boss for help, Crab < / H2 >

bosses can do it if they have other ideas.

v-drag custom instruction supplement

drag: {
      bind: function(el, binding) {
        let oDiv = el; //
        let self = this; //
        oDiv.onmousedown = function(e) {
          //
          let disX = e.clientX - oDiv.offsetLeft;
          let disY = e.clientY - oDiv.offsetTop;

          document.onmousemove = function(e) {
            //
            let l = e.clientX - disX;
            let t = e.clientY - disY;
            //
            oDiv.style.left = l + "px";
            oDiv.style.top = t + "px";
            //
            binding.value({
              id:oDiv.id,
              x: l,
              y: t,
              disX:oDiv.offsetLeft,
              disY:oDiv.offsetTop,
              clientX:e.clientX,
              clientY:e.clientY
            })
          };
          document.onmouseup = function(e) {

            document.onmousemove = null;
            document.onmouseup = null;
          };
        };
      },
Apr.09,2021

<div class="divModule"  v-drag="getData" :id="element.id" v-for="(element,index) in tags" :key="index" style="width:200px;height:200px">
        <divModule  :id="index+1" :property="element" @moduleProperty="getModuleProperty">
        </divModule>
        <div class="bigAndSmall" :id="index+1" v-move="getData" v-drag.stop.prevent>
        </div>
      </div>

it should be feasible to prevent drag events from bubbling in child nodes

add:
according to the code added to the title, I restored a similar scene in jsFiddle .

    el.onmousedown = function(e){
    //
    if(e.target.attributes["data-refuseDrag"]){
        return ;
    }
    

then you need to

  <div class="divModule" v-drag  style="width:200px;height:200px">
        <div class="bigAndSmall" data-refuseDrag="true">
        </div>
      </div>

append a data-refuseDrag attribute to the element that does not need to be dragged, just as in the previous code. You can define

yourself.
Menu