<script>
import Moveable from "vue-moveable";

export default {
    components: { Moveable },
    data() {
        const translate = [0, 0];
        const targetRef = null;
        const moveableRef = null;
        return { translate, targetRef, moveableRef };
    },
    methods: {
        onResize(e) {
            e.target.style.width = `${e.width}px`;
            e.target.style.height = `${e.height}px`;
            e.target.style.transform = e.drag.transform;
        },
        onResizeEnd(e) {
            const lastEvent = e.lastEvent;
            if (lastEvent) {
                console.log(lastEvent.drag.transform);
            }
        }
    },
    mounted() {
        this.targetRef = this.$refs.targetRef;
        this.moveableRef = this.$refs.moveableRef;
    }
};
</script>
<template>
    <div class="root">
        <div
            class="container"
            style="display: flex;"
        >
            <div
                class="target"
                ref="targetRef"
                style="position: relative;width: 200px;height: 100px;"
            >Target</div>
            <Moveable
                ref="moveableRef"
                :target="targetRef"
                :resizable="true"
                :keepRatio="true"
                :throttleResize="1"
                @resize="onResize"
                @resizeEnd="onResizeEnd"/>
        </div>
    </div>
</template>