3、electron读取文本文本文件内容展示到页面
1、项目根目录下创建一个文件文件test.txt
2、index.html页面源码:
<!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8"> <meta name="renderer" content="webkit"> <meta name="force-rendering" content="webkit"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <base href="/"> <title>electron</title> <head></head> <body> <button id="btn">获取文本文件内容</button> <div id="content"></div> </body> <script> let fs = require('fs'); window.onload = function(){ let btn = this.document.querySelector("#btn"); let content = document.querySelector("#content"); btn.onclick = function(){ fs.readFile('test.txt',(err,data)=>{ content.innerHTML = data; }) } } </script>
3、点击按钮