5

Vue app code:

var app = new Vue({
    el: "#APP",
    data: {some data},
    methods: {
            some_method: function() {
                   ......
            }
});

some_js_func = function() {
       "How do I call 'some_method' to here"
};
some_js_func();

I tried by calling app.some_method(), but it's not working.

Jitendra
  • 461
  • 6
  • 15
  • https://stackoverflow.com/questions/33682651/call-a-vue-js-component-method-from-outside-the-component – mrben522 Jan 09 '20 at 14:24

1 Answers1

4

With pure JavaScript, you can access the some_method function via the $options property like this:

var app = new Vue({
    methods: {
            some_method: function() {
                   alert("hello");
            }}
});

someJSfunc = function() {
       app.$options.methods.some_method();
};

someJSfunc();
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
AndrewL64
  • 15,794
  • 8
  • 47
  • 79