Reputation: 3530
I am trying to add the vue-simple-alert package to my Nuxt.js
application but its not working at all. I have followed below steps:
package.json
via command npm install vue-simple-alert --save
.alert.js
under folder plugins
within my nuxt.js project and add following code:import Vue from 'vue'
import { VueSimpleAlert } from 'vue-simple-alert'
Vue.use(VueSimpleAlert)
nuxt.config.js
:plugins: [
{ src: "~/plugins/alert", mode:"client" }
],
Then within my pages/text.vue
I added the alert message as per documentatioin:
this.$alert("Hello Vue Simple Alert.");
The message is displayed as a paragraph text on the Vue page rather than alert message.
I am not understanding whats wrong because I have used other packages similarly and everything worked well with them but same approach does not work for vue-simple-alert
.
Upvotes: 1
Views: 1164
Reputation: 46726
The following configuration works fine.
nuxt.config.js
export default {
ssr: true,
target: 'static',
plugins: [{ src: '~/plugins/alert', mode: 'client' }],
}
/plugins/alert.js
import Vue from 'vue'
import { VueSimpleAlert } from 'vue-simple-alert' // importing like that here, because of the way the package is exported
Vue.use(VueSimpleAlert)
ESlint warning being
Using exported name 'VueSimpleAlert' as identifier for default export.
/pages/index.vue
<template>
<div class="nice">
<button @click="alertMe">hey</button>
</div>
</template>
<script>
export default {
methods: {
alertMe() {
this.$alert('Hello Vue Simple Alert.')
},
},
}
</script>
Upvotes: 1