
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@onesignal/onesignal-vue3
Advanced tools
Vue 3 OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!
This is a JavaScript module that can be used to easily include OneSignal code in a website or app that uses Vue for its front-end codebase.
OneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 2 million+ developers to send 12 billion Push Notifications per day.
You can find more information on OneSignal here.
Upgrading from Version 1? See our migration guide to get started with v2.
Make sure you install a plugin version compatible with your Vue environment.
| Vue | OneSignal Plugin |
|---|---|
| 2 | onesignal-vue |
| 3 | onesignal-vue3 |
Run npm install
yarn add @onesignal/onesignal-vue3
npm install --save @onesignal/onesignal-vue3
yarn add @onesignal/onesignal-vue3
In Vue 3, you can pass in the OneSignal initialization options directly as an argument to the use function. You can still initialize separately if you prefer editor benefits like code-completion.
// main
import { createApp } from 'vue';
import OneSignalVuePlugin from '@onesignal/onesignal-vue3';
createApp(App)
.use(OneSignalVuePlugin, {
appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
})
.mount('#app');
or
//main
import { createApp } from 'vue';
import OneSignalVuePlugin from '@onesignal/onesignal-vue3';
createApp(App).use(OneSignalVuePlugin).mount('#app');
// component
this.$OneSignal.init({
appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
});
The OneSignal plugin automatically exposes a $OneSignal global property accessible inside the application.
You can also leverage Vue's Composition API via the useOneSignal function that can be called from within setup.
The init function returns a promise that resolves when OneSignal is loaded.
Examples
await this.$OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
// do other stuff
this.$OneSignal
.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' })
.then(() => {
// do other stuff
});
You can pass other options to the init function. Use these options to configure personalized prompt options, auto-resubscribe, and more.
| Property Name | Type | Description |
|---|---|---|
appId | string | The ID of your OneSignal app. |
autoRegister | boolean (optional) | Whether or not to automatically register the user. |
autoResubscribe | boolean (optional) | Whether or not to automatically resubscribe the user. |
path | string (optional) | The path to the OneSignal service worker file. |
serviceWorkerPath | string (optional) | The path to the OneSignal service worker script. |
serviceWorkerUpdaterPath | string (optional) | The path to the OneSignal service worker updater script. |
subdomainName | string (optional) | The subdomain of your OneSignal app. |
allowLocalhostAsSecureOrigin | boolean (optional) | Whether or not to allow localhost as a secure origin. |
requiresUserPrivacyConsent | boolean (optional) | Whether or not the user's consent is required. |
persistNotification | boolean (optional) | Whether or not notifications should persist. |
notificationClickHandlerMatch | string (optional) | The URL match pattern for notification clicks. |
notificationClickHandlerAction | string (optional) | The action to perform when a notification is clicked. |
welcomeNotification | object (optional) | The welcome notification configuration. |
notifyButton | object (optional) | The notify button configuration. |
promptOptions | object (optional) | Additional options for the subscription prompt. |
webhooks | object (optional) | The webhook configuration. |
[key: string] | any | Additional properties can be added as needed. |
Service Worker Params You can customize the location and filenames of service worker assets. You are also able to specify the specific scope that your service worker should control. You can read more here.
In this distribution, you can specify the parameters via the following:
| Field | Details |
|---|---|
serviceWorkerParam | Use to specify the scope, or the path the service worker has control of. Example: { scope: "/js/push/onesignal/" } |
serviceWorkerPath | The path to the service worker file. |
If you haven't done so already, you will need to add the OneSignal Service Worker file to your site (learn more).
The OneSignal SDK file must be publicly accessible. You can put them in your top-level root or a subdirectory. However, if you are placing the file not on top-level root make sure to specify the path via the service worker params in the init options (see section above).
Tip:
Visit https://yoursite.com/OneSignalSDKWorker.js in the address bar to make sure the files are being served successfully.
If IntelliSense is not working as expected in your .vue file, try adding an import from the OneSignal plugin.

This package includes Typescript support.
interface IOneSignalOneSignal {
Slidedown: IOneSignalSlidedown;
Notifications: IOneSignalNotifications;
Session: IOneSignalSession;
User: IOneSignalUser;
Debug: IOneSignalDebug;
login(externalId: string, jwtToken?: string): Promise<void>;
logout(): Promise<void>;
init(options: IInitObject): Promise<void>;
setConsentGiven(consent: boolean): Promise<void>;
setConsentRequired(requiresConsent: boolean): Promise<void>;
}
See the official OneSignal WebSDK reference for information on all available SDK functions.
Use listeners to react to OneSignal-related events:
| Event Name | Callback Argument Type |
|---|---|
| 'click' | NotificationClickEvent |
| 'foregroundWillDisplay' | NotificationForegroundWillDisplayEvent |
| 'dismiss' | NotificationDismissEvent |
| 'permissionChange' | boolean |
| 'permissionPromptDisplay' | void |
| Event Name | Callback Argument Type |
|---|---|
| 'slidedownShown' | boolean |
| Event Name | Callback Argument Type |
|---|---|
| 'change' | boolean |
Example
this.$OneSignal.Notifications.addEventListener('change', (event) => {
console.log('The notification was clicked!', event);
});
See the OneSignal WebSDK Reference for all available event listeners.
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Reach out to us via our Discord server!
Copyright © 2023 OneSignal.
This project is Modified MIT licensed.
Enjoy!
FAQs
Vue 3 OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!
We found that @onesignal/onesignal-vue3 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.