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


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); 
		},
	},
};

猜你喜欢

转载自blog.csdn.net/weixin_51157081/article/details/124638850#comments_22036232