Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不使用ts,监听事件有触发,但修改样式不起作用。 #1

Closed
danbaixi opened this issue Jun 29, 2023 · 2 comments
Closed

Comments

@danbaixi
Copy link

使用vue3,没有使用ts的情况,有触发事件,输出的e对象也是正确的,但是修改fill无效。

<script setup>
const rect = new Rect({
  x: 100,
  y: 100,
  width: 200,
  height: 200,
  fill: '#32cd79',
  stroke: 'black',
  strokeWidth: 2,
  draggable: true
})
leafer.add(rect)

function onEnter(e) {
  console.log(e);
  e.fill = '#42dd89'
}

function onLeave(e) {
  e.fill = '#32cd79'
}

rect.on(PointerEvent.ENTER, onEnter)
rect.on(PointerEvent.LEAVE, onLeave)
</script>

这样使用是没有问题的:

<script setup lang="ts">
import { Leafer, Rect, PointerEvent } from 'leafer-ui'
const leafer = new Leafer({ view: window })
const rect = new Rect({
  x: 100,
  y: 100,
  width: 200,
  height: 200,
  fill: '#32cd79',
  stroke: 'black',
  strokeWidth: 2,
  draggable: true
})
leafer.add(rect)
function onEnter(e: PointerEvent) {
  console.log(e);
  (e.current as Rect).fill = '#42dd89'
}

function onLeave(e: PointerEvent) {
  (e.current as Rect).fill = '#32cd79'
}
rect.on(PointerEvent.ENTER, onEnter)
rect.on(PointerEvent.LEAVE, onLeave)
</script>
@liuycy
Copy link

liuycy commented Jun 29, 2023

只把类型删掉就行,上面这段代码把 import 语句和事件里的 current 都删掉了

这样改应该就没有问题

<script setup>
import { Leafer, Rect, PointerEvent } from 'leafer-ui'
const leafer = new Leafer({ view: window })
const rect = new Rect({
  x: 100,
  y: 100,
  width: 200,
  height: 200,
  fill: '#32cd79',
  stroke: 'black',
  strokeWidth: 2,
  draggable: true
})
leafer.add(rect)
function onEnter(e) {
  console.log(e);
  e.current.fill = '#42dd89'
}

function onLeave(e) {
  e.current.fill = '#32cd79'
}
rect.on(PointerEvent.ENTER, onEnter)
rect.on(PointerEvent.LEAVE, onLeave)
</script>

@danbaixi
Copy link
Author

只把类型删掉就行,上面这段代码把 import 语句和事件里的 current 都删掉了

这样改应该就没有问题

<script setup>
import { Leafer, Rect, PointerEvent } from 'leafer-ui'
const leafer = new Leafer({ view: window })
const rect = new Rect({
  x: 100,
  y: 100,
  width: 200,
  height: 200,
  fill: '#32cd79',
  stroke: 'black',
  strokeWidth: 2,
  draggable: true
})
leafer.add(rect)
function onEnter(e) {
  console.log(e);
  e.current.fill = '#42dd89'
}

function onLeave(e) {
  e.current.fill = '#32cd79'
}
rect.on(PointerEvent.ENTER, onEnter)
rect.on(PointerEvent.LEAVE, onLeave)
</script>

感谢,已经解决了。看文档的时候没有留意到还有current这个属性

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants