新手凑活看看 有更好的方法欢迎大神指导
1. 页面
2. js代码 Vue.directive('drag', { inserted(el) { const dialogHeaderEl = el.parentElement const dragDom = dialogHeaderEl.parentElement dialogHeaderEl.style.cssText += ';cursor:move;' dragDom.style.cssText += ';top:0px;' dialogHeaderEl.onmousedown = (e) => { var startX = e.clientX - dragDom.offsetLeft; var startY = e.clientY - dragDom.offsetTop; document.onmousemove = function(e) { var endX = e.clientX - startX; var endY = e.clientY- startY; dragDom.style.left = endX + 'px'; dragDom.style.top = endY + 'px'; } document.onmouseup = function() { document.onmousemove = null; document.onmouseup = null; } } } });