Hello,
How to call a notification component in a .js file?
`'use strict';
export function write(text) {
try {
this.$vs.notify({
title:'Success',
text: text,
color:'success',
iconPack: 'feather',
icon:'icon-check'})
}
catch (e) {
console.log(e);
}
}`
I did it by setting a global.vm = this in created function in main app vue... and in the .js file, I just call vm.$notify
Sorry for my bad English, hope you get my idea
You can place those global functions on a mixin and load it on main.js. They will be accesible everywhere in your app.
Just setup a mixin.js with your helper functions:
export const utilsMixin = {
methods: {
$_utilsMixin_export(text) {
try {
this.$vs.notify({
title: "Success",
text: text,
color: "success",
iconPack: "feather",
icon: "icon-check"
});
} catch (e) {
console.log(e);
}
}
}}
Then on main.js:
Vue.mixin(utilsMixin); // helper functions mixin
And now you can use your function everywhere just calling it:
this.$utilsMixin_export("My text")
Hope it helps,
But it just global for Vue instance, he is asking for using it in .js file, not .vue file... So I think the way I show him is good, right?
@hoatran170999 yes, in that case I guess you are right. But it seems a little strange to call a notify function outside a vue component in a Vue project.
Anyway, with that two examples I think @huseyinyildirimcom can make whatever he wants.
Thank you for your answers. I don't know much about the Vue.js. You're right. In an external file, calling the vue component is bad.
`import Vue from 'Vue'
Vue.prototype.$vs.notify()`
The solution is as follows.
Thank you.
This can be closed @luisDanielRoviraContreras .
Most helpful comment
But it just global for Vue instance, he is asking for using it in .js file, not .vue file... So I think the way I show him is good, right?