The `onesignal-vue` package provides a specialized JavaScript module to seamlessly integrate OneSignal's push notification, in-app messaging, and analytics services into Vue 2 applications. It acts as a wrapper around the core OneSignal Web SDK, simplifying setup and API access within the Vue ecosystem. Currently at version 2.7.0, the library receives frequent minor and patch updates, indicating active maintenance and continuous improvement. Its primary differentiator is its targeted compatibility with Vue 2, offering a `Vue.use()` plugin interface and injecting the OneSignal API directly onto Vue instances as `$OneSignal`. For Vue 3 projects, a separate package, `onesignal-vue3`, is required due to breaking changes in Vue's plugin architecture.
npm install onesignal-vueVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to install the `onesignal-vue` plugin and initialize the OneSignal SDK with an application ID in a Vue 2 application, then prompts the user for push notification permission.
For Vue 3 projects, install `@onesignal/onesignal-vue3` (`npm install --save @onesignal/onesignal-vue3`) instead of `onesignal-vue`.
Refer to the `MigrationGuide.md` in the project repository for detailed steps and necessary code adjustments when upgrading from version 1.
Ensure that subsequent OneSignal API calls are placed inside the `.then()` block of the `init` promise or after an `await this.$OneSignal.init()` call.
Add `import OneSignalVue from 'onesignal-vue';` to the `<script>` section of your `.vue` components where you use `this.$OneSignal`.
Ensure `Vue.use(OneSignalVue)` is called before creating your Vue instance, typically in `main.js` or `app.js`. Also, verify you are using Vue 2 and not Vue 3 with this package.
Verify that `appId` is correctly passed to `this.$OneSignal.init({ appId: 'YOUR_ONESIGNAL_APP_ID' })` and that it is a valid OneSignal Application ID from your dashboard.Ensure your project's `shims-vue.d.ts` or a similar declaration file extends Vue's `ComponentCustomProperties` interface to include `$OneSignal`, or import the plugin within your component's script block for local type inference.