Vue+Electron cookies设置


在网页版Vue中,我使用的是js-cookie这个包来实现cookie的

但是Electron中似乎不可以用,查询官方文档发现有一个cookies的类

于是在此类上重写cookie的get,set的实现

API参考:类:Cookies | Electron (electronjs.org)

const { session } = require('electron')

export default class Cookies {
    getCookies(name){
        const value = session.defaultSession.cookies.get({ url: 'http://www.voiceofhand.com', name: name})
        return value
    }

    setCookies(name, value){
        session.defaultSession.cookies.set({ url: 'http://www.voiceofhand.com', name: name, value: value})
    }
}

 实际使用过程中,在 const { session } = require('electron') 会出现问题,

1、提示了:__dirname is not defined

解决方式:

    webPreferences: {
      
      //支持完整node
      nodeIntegration:true,
      contextIsolation:false
    }

2、提示:Uncaught TypeError: fs.existsSync is not a function at getElectronPath

解决方式:修改为

const { session } = window.require('electron') 

 

 但是还是遇到了

[Vue warn]: Error in created hook: "TypeError: Cannot read property 'defaultSession' of undefined"

这个问题,目前还在找解决方案


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM