> 文章列表 > Javascript——下载功能,获取电脑桌面制定下载路径

Javascript——下载功能,获取电脑桌面制定下载路径

Javascript——下载功能,获取电脑桌面制定下载路径

功能:点击下载按钮获取到用户电脑的桌面信息,可选择指定的下载路径,(结合electron框架,桌面端)

Javascript——下载功能,获取电脑桌面制定下载路径

<el-table-column prop="fileName" label="日志" align="center"><template slot-scope="scope"><div v-show="scope.row.fileName"><i class="el-icon-share"></i><div>{{ scope.row.fileName }}</div><el-button type="text" size="small" @click="downClick(scope.row)">下载文件</el-button></div></template></el-table-column>
 downClick(row) {this.fileDown = row.fileName;var inputObj = document.createElement('input'); // 设置属性inputObj.setAttribute('id', '_ef');inputObj.setAttribute('type', 'file');inputObj.setAttribute('style', 'visibility:hidden');if (row) {// 如果要选择路径,则添加以下两个属性inputObj.setAttribute('webkitdirectory', '');inputObj.setAttribute('directory', '');} // 添加到DOM中document.body.appendChild(inputObj); // 添加事件监听器inputObj.addEventListener('change', this.updatePath); // 模拟点击inputObj.click();},