I have defined some global functions in main.js like this:
Vue.prototype._isMobile = function () {
return $(window).width() < 768
}
//Few more similar functions
Now, I want to move these functions to a separate file called util.js:
return (function () {
import Vue from 'vue'
Vue.prototype._isMobile = function () {
return $(window).width() < 768
}
})();
After creating the util.js file, I added the following code in main.js:
require('util.js')
I tried different variations of this method, including exporting and importing, but none of them worked. Can someone suggest a better way to achieve this?
Edit
In response to suggestions to use a plugin, I created a file named util.js with the following content:
Util.install = function (Vue, options) {
Vue.prototype._isMobile = function () {
return $(window).width() < 768
}
}
Then, in main.js, I included the following code:
import Util from 'util'
Vue.use(Util)
However, I encountered the following error:
Uncaught TypeError: plugin.apply is not a function