OneSignal / onesignal-vue

Vue OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!
Other
13 stars 2 forks source link

Is plugin compliant with vue3 ? #15

Closed this1-it closed 2 years ago

this1-it commented 2 years ago

I see that dependencies are with vue2, but I give a try with vue3

plugin initialization is different, I'm doing:

import { createApp } from 'vue'
const app = createApp(App)
import OneSignalVue from 'onesignal-vue'
app.use(OneSignalVue)

then I got this exception, do you have any clue ? Uncaught TypeError: Cannot set properties of undefined (setting '$OneSignal')

jkasten2 commented 2 years ago

@this1-it Thanks for reporting, this plugin only supports Vue2 currently. We will be looking into adding Vue3 support in the future.

this1-it commented 2 years ago

I've already done the porting in vue3, plugin is loaded but I was not able to test yet because I do not have a valid key

Instead of export default OneSignalVuePlugin;

` I changed your plugin and exported a function as default

export default {
    install: (app: any, options: any) => {
        app.config.globalProperties.$OneSignal = OneSignalVue as IOneSignal;
    }
}
import { createApp } from 'vue'
// this is my OneSignal plugin
import OneSignalVue from "@/onesignal"
const app = createApp(App)
app.use(OneSignalVue)

I think you can handle vue2 in method install like this app.prototype.$OneSignal = OneSignalVue as IOneSignal;