// electron可以直接获取地址
e.target.files[0].path
详细:
uploadFile = () => {
this.referenceUpload.current.dispatchEvent(new MouseEvent("click"));
};
getUpload = (e) => {
console.log(e.target.value);
let file = e.target.files[0];
console.log(file.path);
this.setState({
modelPath:
window.navigator.userAgent.indexOf("Electron") !== -1
? file.path
: e.target.value,
});
};
<div
className={styles.add_algorithm_modal_body_upload_btn}
onClick={this.uploadFile}
>
选择文件
</div>
<input
type="file"
ref={this.referenceUpload}
onChange={this.getUpload}
/>