【问题标题】:Property 'clientX' does not exist on type 'Event' Angular 6“事件”类型 Angular 6 上不存在属性“clientX”
【发布时间】:2019-04-17 17:57:20
【问题描述】:

我正在使用带有 Angular 6 的 TypeScript,并试图利用我的鼠标事件。

但是,根据这段代码:

if (event.clientX < 260){
  return [x + 20, ny - 190]
}
else {
  return [x - 240, ny - 190]
}

我收到一条错误提示

““事件”类型上不存在属性“clientX”。

代码仍按预期运行。

我怎样才能解决这个问题,这样我似乎没有错误? 谢谢!

【问题讨论】:

    标签: angular typescript mouseevent


    【解决方案1】:

    您可以如下声明传递事件的参数类型,

    someFunc(event: MouseEvent): void  { 
      if (event.clientX< 260){
        return [x+20, ny - 190]
      }
      else {
        return [x-240, ny - 190]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-27
      • 2016-08-27
      • 2019-02-01
      • 2018-11-30
      • 2018-11-25
      • 2018-11-04
      • 2017-08-15
      • 2019-04-11
      相关资源
      最近更新 更多