Article From:https://www.cnblogs.com/cssfirefly/p/9121821.html

element ui Upload files, read content to resolve:

Add second parameters

reader.readAsText(file.raw,'gb2312');

 

<el-upload
                            class="upload-demo"
                            ref="upload"
                            
                            :on-change="handleChange"
                            :file-list="fileList"
                            accept = ".txt"
                            :auto-upload="false">
                            <el-button slot="trigger" size="small" type="primary">Select the file < /el-button>< /el-upload>

 

 

 

handleChange(file, fileList) {
                var _this = this;
                if (file.raw) {                    
                    let reader = new FileReader()  
                    reader.onload = function (e) {
                       _this.contentHtml = e.target.result;
                    };
                    reader.readAsText(file.raw,'gb2312');
                
                }
                console.log(file, fileList);
            },

 

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *