After setting up a plugin named helper.js inside plugins/ directory, I encountered an issue where the plugin's functions did not work when called inside another function. Below is my code snippet for helper.js:
import Vue from 'vue'
import $ from 'jquery'
import toastr from 'toastr'
Vue.mixin({
methods: {
test () {
alert('test is called correctly')
}
}
})
Here is the code snippet for pages/index.vue:
mounted () {
/** Create the cartesian option for products variants **/
const classname = document.getElementsByClassName('main-input')
// calling the cartesian function from plugins/helper.js and listening to each .main-input class on change
const myFunction = function () {
this.test()
}
for (let i = 0; i < classname.length; i++) {
classname[i].addEventListener('keyup', myFunction)
}
}