Vue中使用vue-draggable-resizable实现可拖动悬浮组件
首先运行命令安装引入组件
npm install --save vue-draggable-resizable
引入完成之后,便可以使用了;
我这里是封装成了组件,方便其他页面引用,写法如下:
<template>
<vue-draggable-resizable class="top-toolbar-wrapper" :w="toolbarWidth" :h="toolbarHeight" :x="canvasX" :resizable="false" :parent="true" @dragging="onDrag" @resizing="onResize">
<div class="draggable">
内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容
</div>
</vue-draggable-resizable>
</template>
</template>
<script type="text/javascript">
import VueDraggableResizable from 'vue-draggable-resizable';
export default {
components: {
VueDraggableResizable
},
mounted() {
},
data() {
return {
toolbarWidth: "auto", //宽度
toolbarHeight: 44, //高度
canvasX: 360 //初始距离左侧偏移量
}
},
methods: {
onDrag(x, y) {
},
onResize(x, y, width, height) {
}
}
}
</script>
<style lang="scss">
.top-toolbar-wrapper {
z-index: 10000 !important;
position: fixed !important;
border: 0px !important;
top: 4px;
cursor: pointer;
.draggable {
width: 100%;
height: 100%;
background: red;
}
}
</style>