Get Local yaml json or other content file, displayed in the edit box

iview framework can be used upload component can transfer files, but can not read the contents of the file

Currently the background do not need to transfer a file, simply transfer the file contents as a string, you can use an object in HTML5 FileReader

<input type="file" class="file" @change="tirggerFile($event)">
<Button @click="readFile">上传</Button>

After uploading

|| We == 'yaml || We == 'CFG'
) { The this .readFile (); } the else { the this . $ Notice.error ({ title: 'Please re-click to select the incoming file compliant file' , DURATION: 2 }); } }, readFile () { the let Self = the this ; the let fileselect = document.querySelector ( 'the INPUT [of the type = file]') files [0];. // find the file upload element of the let Reader = new new FileReader () //console.log (fileselect); IF ( typeof FileReader === 'undefined' ) { Alert ( 'Your browser does not support FileReader Interface' ); } reader.readAsText (fileselect, 'GB2312') // note read Chinese this code is to use, instead. 8-UTF reader.onload = function () { the console.log (reader.result); // file content } },

Finally, the contents of the file obtained can be assigned to a text edit box

 

Guess you like

Origin www.cnblogs.com/xu-nian-qin/p/11125558.html