3

On the vuejs.org website there is this function. vuejs function I want to replicate this to test some code i am writing in an on click function on a table row using jquery.

   $("#table1 tr").click(function () {
            // alert($(this).text());
            //  alert($(this).children("td").html());
            // app.greet();
        });

I want to call the vue function there but my vue code is written in the script and i am using export default like so.

export default {
    data() {
        return {

        }
etc.
}

If i want to use this vue function in jquery how do i call it.

2 Answers 2

8

You have to instantiate the App, then you can call the method on it:

import Vue from 'vue'
import App from './app.vue'

const app = new Vue(App)

$("#table1 tr").click(function () {
  app.greet()
})
Sign up to request clarification or add additional context in comments.

3 Comments

can i do this in separate components
also when you say import app from app.js do i import my app.vue file there or my main.js file.
@DanielM96 The .vue file. I edited my answer accordingly.
0
export default {
  mounted(){
     $("#table1 tr").on('click',()=> {
        this.greet()
     });
  },

  methods:{
    greet(){
      console.log('greet method')
    }
  }
}

1 Comment

Your answer could be improved by adding more information on what the code does and how it helps the OP.

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.