一番码客 : 挖掘你关心的亮点。 http://efonfighting.imwork.net
本文目录:
前言vue中实现代码实际效果一番今日
前言
我们在开发electron桌面应用时,因为常常希望对一些本地文件做一些操作,需要获取到这个文件的绝对路径。今天一番在electron-vue下实现了单击按钮选择文件,并获取文件绝对路径然后显示出来的效果。在本来要放弃的时候突然柳暗花明。
vue中实现
代码
这里涉及到在vue中定义和调用函数,需要用到关键字methods,然后便可以在里面定义函数了。
这里关键点:
document.getElementById('open').files[0].path,这里获取文件路径的方法是获取文件类元素的数组,然后通过path关键字获取文件的绝对路径。
<template>
<div id="wrapper" align="center">
<img id="logo" src="~@/assets/logo_efonmark.png" alt="electron-vue" align="center">
<div align="center">
<h1> Welcome to EfonMark!</h1>
</div>
<div align="center">
<el-input id="input01"
type="textarea"
:autosize="{ minRows: 2, maxRows: 10}"
placeholder="请选择文件"
v-model="textarea">
</el-input>
</div>
<div align="center">
<el-button type="primary" v-on:click="openFile()" round>选择文件</el-button>
<el-button type="primary" v-on:click="showRealPath()" round>显示路径</el-button>
<input type="file" name="filename" id="open" style="display:none" />
</div>
</div>
</template>
< >
export default {
data() {
return {
textarea: ''
}
},
methods: {
openFile: function () {
document.getElementById('open').click()
},
showRealPath: function () {
document.getElementById('input01').value = document.getElementById('open').files[0].path
}
}
}
</ >实际效果
点击“选择文件”,可以选中一个本地文件;
点击显示路径,可以将刚刚选择的文件的本地绝对路径显示在文本框内。
继续阅读与本文标签相同的文章
上一篇 :
python中实现字符串翻转的方法
-
-35℃至54℃稳定运行,格力这款压缩机在广交会吸睛无数!
2026-05-15栏目: 教程
-
手机老是提示内存不足?清理了还是没用?你需要更深层的清理
2026-05-15栏目: 教程
-
趋势,康宁光通信中国陈皓:数据中心用多模光纤技术及发展
2026-05-15栏目: 教程
-
赢在项目管理,如何正确把握需求?
2026-05-15栏目: 教程
-
生命在于休息,脑子不想事情更长寿?
2026-05-15栏目: 教程
