学无先后,达者为师

网站首页 Vue 正文

vue+elementUi+el-upload实现上传、获取本机文件路径、获取本机服务器路径、电脑盘符、createObjectURL、getElementsByClassName

作者:web半晨 更新时间: 2022-06-05 Vue


1、HTML

<el-upload
	action=""
	:limit="1"
	:on-change="handleChange"
	:auto-upload="false"
	:file-list="fileList"
	:show-file-list="false"
>
	<span>选择文件</span>
</el-upload>

2、JavaScript

export default {
	data() { 
		return {};
	},

	methods: {
		// 选择文件
		handleChange(file, fileLists) {
			console.log(file);
			console.log(fileLists);
			// 本地服务器路径
			console.log(URL.createObjectURL(file.raw));
			// 本地电脑路径
			console.log(document.getElementsByClassName("el-upload__input")[0].value); 
		},
	},
};

原文链接:https://blog.csdn.net/weixin_51157081/article/details/124638850

栏目分类
最近更新