ci010 / electron-vue-next

A starter template for using vue-next with the electron.
https://ci010.github.io/electron-vue-next/
191 stars 27 forks source link

useIpc().on is not a function #36

Closed carlosyan1807 closed 3 years ago

carlosyan1807 commented 3 years ago

src/main/index.ts

function createWindow() {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    height: 600,
    width: 800,
    webPreferences: {
      preload: join(__static, 'preload.js'),
      contextIsolation: true,
      nodeIntegration: false,
    },
  })

src/renderer/index.ts

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

const app = createApp(App)
app.use(router).mount('#app')

src/renderer/App.vue

import { useIpc } from './hooks'

export default {
  name: 'App',
  created() {
    useIpc().on('main2renderer', (event, arg) => {
      console.log(event, arg)
    })
  },
}

console

TypeError: useIpc(...).on is not a function
    at Proxy.created (D:\projects\learning\src\renderer\App.vue:12)
    at callWithErrorHandling (runtime-dom.esm-bundler-98b8ebd7.js:1300)
    at callWithAsyncErrorHandling (runtime-dom.esm-bundler-98b8ebd7.js:1309)
    at callSyncHook (runtime-dom.esm-bundler-98b8ebd7.js:7040)
    at applyOptions (runtime-dom.esm-bundler-98b8ebd7.js:6971)
    at finishComponentSetup (runtime-dom.esm-bundler-98b8ebd7.js:7649)
    at setupStatefulComponent (runtime-dom.esm-bundler-98b8ebd7.js:7582)
    at setupComponent (runtime-dom.esm-bundler-98b8ebd7.js:7522)
    at mountComponent (runtime-dom.esm-bundler-98b8ebd7.js:5264)
    at processComponent (runtime-dom.esm-bundler-98b8ebd7.js:5240)

useIpc().send('xxx') and ipcMain.on works ok how does ipcRenderer receive messages ?

carlosyan1807 commented 3 years ago

I was so stupid. 😢 I'll read the document carefully next time.

2234839 commented 3 years ago

I was so stupid. 😢 I'll read the document carefully next time.

I'm having the same problem as you, but I don't know what I'm doing wrong yet, please advise your solution, thanks!


I've got the solution from here: https://github.com/ci010/electron-vue-next/issues/49