TypeError: Cannot read property 'clipboard' of undefined
-
I am adding copy to clipboard functionality on my app (using Electron).
I use this command:
methods: { copyToClipboard () { if (process.env.MODE === 'electron') { this.$q.electron.clipboard.writeText(this.logText) } } }
But then I get an error message:
TypeError: Cannot read property 'clipboard' of undefined
I wonder why. On a separate vue file (main layout vue), I also call
this.$q.electron
functions (minimize, maximize, etc) and they work fine. The same functions when I try using this component also generates the same error.I initially used to do this but I need to change implementation since this doesn’t work when I build for web (I use web for Cypress testing):
const { clipboard } = require('electron') clipboard.writeText(this.logText)
Is
this.$q.electron
only allowed to be used on certain files/levels? -
Nevermind. Fixed this by using the built-in Quasar functoin copyToClipboard() instead.
import { copyToClipboard } from 'quasar'
Thanks