7

vue typescript event 的数据类型怎么表示?

 2 years ago
source link: https://www.v2ex.com/t/824302
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Vue.js

vue typescript event 的数据类型怎么表示?

  GhostBoy · 1 小时 23 分钟前 · 86 次点击


function readFile(event): void {
    const file = event.target.files[0];
    console.log(file.name);
};


在 vscode 里 function readFile(event): void { 中的 event 总是有红色波浪线! 想请教一下如何解决?

1 条回复    2021-12-24 19:16:47 +08:00

wunonglin

wunonglin      1 小时 7 分钟前

```js
function readFile(event: Event): void{
const input = event.target as HTMLInputElement
const file = input.files.item(0) || undefined
if (file){
巴拉巴拉
}
}
```

或者

```js
function readFile(event: Event): void{
const input = event.target as any
if (input instanceof HTMLInputElement){
const file = input.files.item(0) || undefined
if (file){
巴拉巴拉
}
}
}
```


大概是这样。手写的没用编辑器,有错请指正。。。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK