DanielM96
DanielM96

Reputation: 103

How to call a vuejs function in jquery if your using vue with export default

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.

Upvotes: 3

Views: 11450

Answers (2)

amirreza sharifi
amirreza sharifi

Reputation: 31

export default {
  mounted(){
     $("#table1 tr").on('click',()=> {
        this.greet()
     });
  },

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

Upvotes: 0

Daniel Diekmeier
Daniel Diekmeier

Reputation: 3434

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()
})

Upvotes: 8

Related Questions