久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

vue + electron 如何將文件寫入磁盤

vue + electron how to write a file to disk(vue + electron 如何將文件寫入磁盤)
本文介紹了vue + electron 如何將文件寫入磁盤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 Vue 和 Electron 構建一個桌面應用程序.我想從一個 vue 組件中保存一個文件,其中包含用戶介紹的一些數據.為此,我嘗試在 vuex 操作中使用 fs 節點模塊,但它讓我出錯.找不到那個模塊.我知道 Vue 是客戶端,但是,我認為在與 Electron 一起使用時它可以工作,但事實并非如此.為了初始化我的應用程序,我使用了 vue-cli 和命令 vue init webpack electron-vue.我正在使用 vuex 系統和 vuex 模塊,我有一個 actions.js 文件,我嘗試使用 fs 模塊:

I'm building a desktop app using Vue and Electron. I want to save a file from a vue component with some data introduced by the user. For doing that, I tried used fs node module inside an vuex action, but it got me error. Can't found that module. I know Vue is client side, but, I thought that at the moment of using with Electron it could work, but it does't. To init my app I used vue-cli and the command vue init webpack electron-vue. I'm using vuex system and using vuex modules too, I've an actions.js file where I tried to use the fs module:

// import * as fs from 'fs'; I used this way at first
const fs = require('fs');
export const writeToFile = ({commit}) => {
 fs.writeFileSync('/path/file.json', JSON.stringify(someObjectHere));
};

當我從 Vue 組件(例如 Options.vue)調用此操作時,我使用 vuex 調度系統,并且在該組件的 created() 方法中:

When I call this action from a Vue component, ex, Options.vue, I use the vuex dispatch system, and, in the created() method of that component:

this.$store.dispatch('writeToFile')

這引起了我上面提到的錯誤

That's raised me the error above mentioned

推薦答案

要在electron中使用文件系統與Vue和WebPack,文件系統實例必須在執行命令npm run"后在dist/index.html中聲明構建"

to use File System in electron with Vue and WebPack, the file system instance has to be declared in the dist/index.html after execute the command "npm run build"

<script>
    var fs = require('fs');
</script>

在 vue 組件中,它使用 fs 就像在 vue 文件中聲明一樣.

and in the vue component, it 's used fs like if it would have been declared in the vue file.

...
export const writeToFile = ({commit}) => {
    fs.writeFileSync('/path/file.json', SON.stringify(someObjectHere))
};
...

如果不在 electron 中使用,或者將其寫入 dev 的索引中,則會引發錯誤.

while if not use it in electron or you write it in the index to dev, it throws an error.

這篇關于vue + electron 如何將文件寫入磁盤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
How to getCurrentPosition via navigator.geolocation in Electron app?(如何通過電子應用程序中的 navigator.geolocation 獲取當前位置?)
主站蜘蛛池模板: 精品国产欧美一区二区三区不卡 | 国产精品久久久久久吹潮 | 中文字幕蜜臀 | 91视频在线网站 | 久久久久成人精品亚洲国产 | 日韩在线视频一区 | 成人一区二区视频 | 成人影院午夜 | 亚洲一区中文 | 久久国产精品久久 | 久草网址| 成人av一区二区在线观看 | 国产欧美一区二区三区免费 | 午夜www| 中文字幕乱码一区二区三区 | 婷婷丁香综合网 | 精品福利视频一区二区三区 | 色婷婷一区二区三区四区 | 中文字幕在线播放第一页 | 福利久久| 懂色av色香蕉一区二区蜜桃 | 欧美一级二级三级 | 麻豆成人在线视频 | 成年人在线观看 | 国产乱肥老妇国产一区二 | 91精品综合久久久久久五月天 | 在线观看成人精品 | 亚洲一级毛片 | 国产精品不卡 | 亚洲精品视频免费 | 日韩欧美在线播放 | 777毛片| 99久久婷婷国产综合精品电影 | 欧美一级精品片在线看 | www.久草.com| 精品中文在线 | 1区2区3区视频 | 亚洲一区二区三区在线免费观看 | 成av在线 | 久久成人精品视频 | 国产色|