Vuejs实现拖拽效果

时间:2022-11-03 14:50:21

<body>
<div class="main">
<div class="left" v-bind:style="{width:ths[0].width+'px'}"></div>
<div class="right" @mousedown="drag"></div>
</div>
<script>
var vm1=new Vue({
el:'.main',
data:{
ths:[
{width:'30'},
{width:''}
]
},
methods:{
drag:function(e,index){

var Left=e.target.parentNode.children[0],
leftW=Left.offsetWidth,
startX=e.clientX;
_this=this;
console.log(_this);

document.onmousemove=function(e){
e.preventDefault();
var distX=e.clientX-startX;
Left.style.width=leftW+distX+'px';
if(parseInt(Left.style.width)>=280){
Left.style.width=280+'px';
}
}

document.onmouseup=function(){
document.onmousemove=null;
}
}
}
});
</script>
</body>