-
Notifications
You must be signed in to change notification settings - Fork 13
Usage (Vue)
Dionlee Uy edited this page Apr 19, 2023
·
5 revisions
In your app.js
import Vue from 'vue'
import vueToast from '@dmuy/toast/vue-toast'
Vue.use(vueToast)
In your app.js
import { createApp } from 'vue'
import vueToast from '@dmuy/toast/vue3-toast'
const app = createApp({
/* root component options */
})
app.use(vueToast)
In the plugins
folder, create mdtoast.js
and paste the Vue 2 script above.
In nuxt.config.js
export default {
plugins: [
'@/plugins/mdtoast.js'
]
}
Create a plugin file plugins/mdtoast.client.js
.
import vueToast from '@dmuy/toast/vue3-toast'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(vueToast)
})
Note: This method is not yet tested.
In your components or pages, you can access the mdtoast()
as this.$mdtoast()
// script
export default {
mounted() {
// default
this.$mdtoast('This is a toast message!')
// with options
this.$mdtoast('Message archived', { type: 'success' })
}
}
In your <script setup>
import { inject } from 'vue'
const mdtoast = inject('mdtoast')
// then use like
function toast(message) {
mdtoast('This is a toast message!')
}