Import and export txt file txt

Export:

this.download ( 'filename', 'Export content');
download=(filename, text)=> {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
};

导入:

<input id='file' type="file" onChange={(e)=>{this.handleUpload(e)}} />
= HandleUpload (E) => { 
const Reader the FileReader new new = ();
// read the contents of the file using TXT readAsText
reader.readAsText (e.target.files [0]);
reader.onload = function (E) {
// console.log (e.target.result); // read result is stored in a string
// let my_str = e.target.result; // save all data directly to a string
// let my_arr = my_str.split (/ [\ s \ n] /); // spaces and line breaks by cutting string, and stored in the array
var {Data =
the params: [{
value: e.target.result e.target.result: '? '
}]
};
    // after introducing transmission interface
$ http.post (' URLS ', the this, {
code: "010",
Data: Data,
Success: function (RES) {
if (res.errorCode === '0') {
console.log('成功')
}
}
});
}.bind(this);


};

Guess you like

Origin www.cnblogs.com/zxm1993/p/12524432.html