to include beatiful flash messages to mey Laravel + vue.js app, so I found a npm package on GitHub and installed this in my app (npm install)
I’m beginner in VueJs and I’m facing a problem: I just can’t use the package in my vue.js components since it throw errors when I try to include this
What I use and what I get:
it’s my app.js code
window.vue.js = require(‘vue’);
/*including the package*/
import FlashMessage from ‘@smartweb/vue-flash-message’;
Vue.use(FlashMessage);
/*including the package*/
Vue.component(‘settings-form’,require(‘./components/SettingsFormComponent.vue’).default);
Vue.component(‘profile-nav’,require(‘./components/ProfileNavComponent.vue’).default);
const app = new Vue({
el: ‘#app’,
});
What error I get using the code:
“TypeError: Cannot read property ‘flashMessage’ of undefined at app.js:1863”
I run this method (flashMessage) when to output a message:
Also I tried to use this code in my app.js to include the packange:
Vue.component(‘FlashMessage’, require(‘@smartweb/vue-flash-message’).default);
but it doesn’t work too, it throws this error:
“Failed to mount component: template or render function not defined …”
I’m trying to use my component that way (in ProfileNavComponent.vue):
<FlashMessage></FlashMessage>
Could you please tell me what the problem can be in?
thanks guys for any help)
I really appreciate this!
Solution :
I usually use vue.js packages adding them from the name of the package, try:
import FlashMessage from ‘vue-flash-message’;
And when you want to use the component, try to use FlashMessage.show().