HTML
<div class="宽度要变化的div">
<div class="拖拉的块" v-move></div>
</div>
CSS
.宽度要变化的div{
position:relative;
width:100px;
height:300px;
}
.拖拉的块{
height: 100%;
width: 10px;
opacity: 0;
position: absolute;
right: 0;
top: 0;
cursor: col-resize;
}
JS
export default {
directives: {
move(el, bindings) {
el.onmousedown = function(e) {
var init = e.clientX;
var parent = document.getElementById("宽度要变化的div");
var initWidth = parent.offsetWidth;
document.onmousemove = function(e) {
var end = e.clientX;
var newWidth = end - init + initWidth;
parent.style.width = newWidth + "px";
};
document.onmouseup = function() {
document.onmousemove = document.onmouseup = null;
};
};
}
}
}