I have to call a Vue.js function from an external JavaScript file, but it's not working. Below I have given the code that I have tried.
// external js file
import vm from './vue.js';
function callingVuejsFunction(data) {
this.vm.displayData()
}
// Vuejs file
var vm = new Vue({
el: '#app',
data: {
firstname : '' ,
lastname : ''
},
methods:{
displayData: function( ) {
alert()
}
}
})
vm.displayData()insteadthis.vm.displayData()main.jsin your Vue application so that it assigned the root Vue instance to a global variable (e.g.window.myApp) and then refer to this variable in your external script.