vue3+element-plus
点击按钮获取本地路径
<el-button size="small" type="primary" onclick="document.getElementById('file-input').click()">选择路径</el-button>
<input type="file" id="file-input" @change="(e) => {console.log('获取到本地路径:',e.target.value)}" style="visibility: hidden;"/>
获取的e.target.value值类似于C:\fakepath\index.html
,对这个值做处理处理成C:/fakepath/
let path: string = e.target.value;
let pArr = path.split('\\');
pArr.pop();
path = pArr.join('/') + '/';