【问题标题】:konva 2D drawing - can i send another variable in mouse down event?konva 2d绘图 - 我可以在鼠标下发送另一个变量吗?
【发布时间】:2021-07-28 18:09:19
【问题描述】:

我想在鼠标事件中发送另一个值,因为我的 handleMouseDown 函数在另一个文件中。

stage.on('mousedown', handleMouseDown(evt, stage))

但我得到了错误:

- Argument of type 'void' is not assignable to parameter of type 'KonvaEventListener<Stage, MouseEvent>'.ts(2345)
- Cannot find name 'evt'.ts(2304)

我尝试从初始化文件导出我的阶段,然后导入另一个文件,但我无法从导出默认值导出值

import { handleMouseDown } from './stageEvents'
export default (): void => {
  export const stage: Stage = new Konva.Stage({
    container: 'container',
    height: 500,
    width: 500
  })
  // bind stage event
  stage.on('mousedown', handleMouseDown)

错误:此处不能出现修饰符

请问有人有什么想法吗?

【问题讨论】:

    标签: typescript konvajs konva


    【解决方案1】:

    您可能想要这样做:

    stage.on('mousedown', (evt) => handleMouseDown(evt, stage));
    

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 1970-01-01
      • 2021-02-09
      • 2011-03-15
      相关资源
      最近更新 更多