/** * v-dialogDragWidth å¯æ‹–动弹窗宽度(å³ä¾§è¾¹ï¼‰ */ export default { bind(el) { const dragDom = el.querySelector('.el-dialog'); const lineEl = document.createElement('div'); lineEl.style = 'width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;'; lineEl.addEventListener('mousedown', function (e) { // é¼ æ ‡æŒ‰ä¸‹ï¼Œè®¡ç®—å½“å‰å…ƒç´ è·ç¦»å¯è§†åŒºçš„è·ç¦» const disX = e.clientX - el.offsetLeft; // 当å‰å®½åº¦ const curWidth = dragDom.offsetWidth; document.onmousemove = function (e) { e.preventDefault(); // 移动时ç¦ç”¨é»˜è®¤äº‹ä»¶ // 通过事件委托,计算移动的è·ç¦» const l = e.clientX - disX; dragDom.style.width = `${curWidth + l}px`; }; document.onmouseup = function (e) { document.onmousemove = null; document.onmouseup = null; }; }, false); dragDom.appendChild(lineEl); } }