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.

1

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

4 Comments

why dont call the method directly: app.some_method(); ?
@Imarqs, this this not possible in Vue2 I guess.
Worked for me like this window.someJSfunc = function() { app.$options.methods.some_method(); };
with the app object, you can call app.some_method(); directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.