我正在将来自浏览器的File
对象(通过拖放)传递给这样的函数:
// .... logic here...
accept(file)
public static accept(file: File) {
console.log(file)
/* prints:
=> lastModified: 1555453309243
lastModifiedDate: Wed Apr 17 2019 01:21:49 GMT+0100 (GMT+01:00) {}
name: "test.txt"
path: "test.txt" --> as you can see there is a path variable in here.
size: 16
type: "text/plain"
webkitRelativePath: ""
__proto__: File
*/
console.log(file.name) // => prints 'test.txt'
console.log(file.size) // => prints '16'
console.log(file.path) // => !! error given. path does not exists in File object. Also IDE does not show this parameter in IDE autocomplete list.
}
给出错误:
Property 'path' does not exist on type 'File'.ts(2339)
为什么File
没有path
参数?如何确保路径存在? File
还有其他类型吗?这是HTML5拖放。
如果我这样做:
public static accept(file: any) {
alert(file.path);
}
它显示了相对路径: