vue 读取本地文件内容
将本地文件中内容显示在页面上<el-button type=“success” id=“fileImport” v-on:click=“clickLoad”>浏览</el-button><inputtype=“file”id=“files”ref=“refFile” style=“display: none”v-on:change=“fil...
·
将本地文件中内容显示在页面上
<el-button type=“success” id=“fileImport” v-on:click=“clickLoad”>浏览</el-button>
<input type=“file” id=“files” ref=“refFile” style=“display: none” v-on:change=“fileLoad” />
fileLoad() {
const selectedFile = this.$refs.refFile.files[0];
var reader = new FileReader();
reader.readAsText(selectedFile);
reader.onload = (e) => {
console.log(e.target.result);
this.tableData = [
{
num: "1",
name: "添加-王小虎",
IP: "000",
address: "上海市普陀区金沙江路 1514 弄"
},
];
};
},
clickLoad() {
this.$refs.refFile.dispatchEvent(new MouseEvent("click"));
}
更多推荐
已为社区贡献5条内容
所有评论(0)