zoukankan      html  css  js  c++  java
  • eldialog添加拖拽功能

    import Vue from 'vue'
    
    Vue.directive('dialogDrag', {
      bind(el, binding, vnode, oldVnode) {
        const dialogHeaderEl = el.querySelector('.el-dialog__header')
        const dragDom = el.querySelector('.el-dialog')
        dialogHeaderEl.style.cursor = 'move'
    
        const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
    
        dialogHeaderEl.onmousedown = (e) => {
          const disX = e.clientX - dialogHeaderEl.offsetLeft
          const disY = e.clientY - dialogHeaderEl.offsetTop
    
          let styL, styT
          if (sty.left.includes('%')) {
            styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
            styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
          } else {
            styL = +sty.left.replace(/\px/g, '')
            styT = +sty.top.replace(/\px/g, '')
          }
    
          document.onmousemove = function(e) {  
            const l = e.clientX - disX
            const t = e.clientY - disY
    
            dragDom.style.left = `${l + styL}px`
            dragDom.style.top = `${t + styT}px`
    
            // 将此时的位置传出去
            // binding.value({x:e.pageX,y:e.pageY})
          }
    
          document.onmouseup = function(e) {
            document.onmousemove = null
            document.onmouseup = null
          }
        }
      }
    })
    

      在directives目录中新建v-drag.js,将以上代码拷贝进去

      创建vdireactive.js

    import drag from './v-drag';
    
    export { drag };
    

    index.js中代码如下

    import Vue from 'vue';
    import * as directives from '@/common/directives/vdirectives.js';
    // 注册指令
    Object.keys(directives).forEach(k => Vue.directive(k, directives[k]));
    

      

    在main.js中引入

    import '@/common/directives'
    

      

    代码搬运工
  • 相关阅读:
    java线程池及创建多少线程合适
    消息队列消息积压了怎么办?
    Redis线程模型
    redis单线程如何支持高并发
    基于redis实现分布式锁
    PHP面试总结
    【转】Redis入门
    面试常考之二叉树
    计算机网络之面试常考
    操作系统之面试常考
  • 原文地址:https://www.cnblogs.com/tw6668/p/15629659.html
Copyright © 2011-2022 走看看