TypeError: Cannot read property 'clipboard' of undefined when calling this.$q.electron.clipboard

TypeError: Cannot read property 'clipboard' of undefined when calling this.$q.electron.clipboard

我正在我的应用程序上添加复制到剪贴板功能(使用 Electron)。

我使用这个命令:

methods: {
   copyToClipboard () {
       if (process.env.MODE === 'electron') {
            this.$q.electron.clipboard.writeText(this.logText)
       }
   }
}

但随后我收到一条错误消息:

TypeError: Cannot read property 'clipboard' of undefined 

我不知道为什么。在一个单独的 vue 文件(主布局 vue)上,我还调用了 this.$q.electron 函数(最小化、最大化等),它们工作正常。当我尝试使用此组件时,相同的功能也会产生相同的错误。

我最初是这样做的,但我需要更改实现,因为当我为 web 构建时这不起作用(我使用 web 进行 Cypress 测试):

const { clipboard } = require('electron')
clipboard.writeText(this.logText)

是否this.$q.electron只能用于某些files/levels?

没关系。通过使用内置的 Quasar 函数 copyToClipboard() 来解决这个问题。

import { copyToClipboard } from 'quasar'

谢谢