插件使用:
DataV Vue3+TS+Vite版 | DataV - Vue3
遇到问题:
动态修改宽高的时候未能即使变化:
解决:
1. 使用作者封装的initWH
方法
2. 设置动态的key,宽高变化就更新
我这边宽高可以拖拽修改,所以设置key更适用一些,代码如下:
<template>
<div :style="styleObj">
<Decoration1 :key="key"/>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { Decoration1} from '@kjgl77/datav-vue3';
const props = defineProps({
w: Number,
h: Number,
});
const key = computed(() => {
return props.w + props.h + Math.random();
});
const styleObj = computed(() => {
const res: Record<string, any> = {
width: props.w + 'px',
height: props.h + 'px',
};
return res;
});
</script>