关于组件更新时的样式改变? #12193
Unanswered
xiaofanghao
asked this question in
Help/Questions
关于组件更新时的样式改变?
#12193
Replies: 1 comment 2 replies
-
直接修改DOM元素的话之后就不要让组件更新 <script setup>
...
const currentStyle = reactive({})
const handleMousMove = (e) => {
...
currentStyle.left = ...
currentStyle.top = ...
}
</script>
<template>
<div ... @mousemove="handleMousMove" class="absolute" :style="currentStyle"></div>
</template> |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
这是组件的开头
这是修改逻辑
//鼠标移动
const onMouseMove = (e: MouseEvent) => {
if (!moveStatus || !dragContainer.value || !dragStyle) return;
let boxWidth = parseFloat(dragStyle.width)
let boxHeight = parseFloat(dragStyle.height)
const newLeft = Math.min(window.innerWidth - boxWidthscreenStore.screenScale, Math.max(0, e.clientX - offsetX));
const newTop = Math.min(window.innerHeight - boxHeightscreenStore.screenScale, Math.max(0, e.clientY - offsetY));
dragContainer.value.style.left =
${(e.clientX-offsetX*screenStore.screenScale)}px
;//相当于鼠标水平位置左移鼠标在弹窗的位置dragContainer.value.style.top =
${(e.clientY-offsetY*screenStore.screenScale)}px
;//跟上面类似}
请问在组件更新时以哪个为准?
我想以拖拽后的结果为准如何修改?
Beta Was this translation helpful? Give feedback.
All reactions