带有 flex/grid 包装器的 vue transition-group 项目移动到左上角

vue transition-group item with flex/grid wrapper moves to top-left

我有这个:

<transition-group
    name="product-list"
    tag="section"
    class="product-list"
    @before-leave="beforeLeave"
>
    <product
        v-for="watch in watches"
        :key="watch.id"
        :item="watch"
    >
    </product>
</transition-group>

正如文档中所说:

.product-list-enter-active,
.product-list-leave-active {
    transition: all 0.3s;
}
.product-list-enter,
.product-list-leave-to {
    opacity: 0;
    transform: scale(0.5);
}
.product-list-leave-active {
    position: absolute;
}

问题:当任何元素离开时(从列表中删除)由于位置绝对,它会移到左上角 ...这有点破坏它的美感

找到这个解决方案:

<transition-group
    @before-leave="beforeLeave">
    ...
</transition>
methods: {
    beforeLeave(el) {
        const {marginLeft, marginTop, width, height} = window.getComputedStyle(el)

        el.style.left = `${el.offsetLeft - parseFloat(marginLeft, 10)}px`
        el.style.top = `${el.offsetTop - parseFloat(marginTop, 10)}px`
        el.style.width = width
        el.style.height = height
    }
}

感谢 docmars 在 forum.vuejs.org

如果有更好的解决方案请告诉我