So, I've started using the Vue Composition API, and it's brilliant. I'm using it in a project that has Vue components, but also Vanilla JS. I'm building a notification system in Vue, as we are slowly moving everything that way.
I have the following code currently for adding a notification
export const useNotification = () => {
const notifications = ref([]);
const visibleNotifications = computed(() => {
return notifications.value.filter(notification => notification.visible === true).reverse();
});
const add = (notification: Notification) => {
notifications.value.push(notification);
};
};
I can get this adding perfectly from within Vue, but I want to also add a notification from the vanilla JS parts of the system. I've tried using useNotification().add()
but I get the following error [vue-composition-api] must call Vue.use(plugin) before using any function.
Basically, it wants me to use it inside Vue.
Any ideas on how I get this working?
vue-composition-api
withvue2
. If you were to usevue3
, it should be fine. – Daniel