一、创建自定义指令文件
在utils文件夹下创建 floatMove.ts 文件
// 拖拽的指令
const drag = {
beforeMount(el: any, binding: any,) {
// 自定义属性,判断是否可拖拽
if (!binding.value) return
// 获取自定义指令所在的dom元素
const dialogHeaderEl = el.querySelector('.dialog_header')
const dragDom = el.querySelector('.dialog_content')
dialogHeaderEl.style.cssText += ';cursor:move;'
dragDom.style.cssText += ';bottom:45%;' //初始化位置
// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
const sty = (function () {
if ((document.body as any).currentStyle) {
// 在ie下兼容写法
return (dom: any, attr: any) => dom.currentStyle[attr]
}
return (dom: any, attr: any) => getComputedStyle(dom, null)[attr]
})()