A
A
Alexander Sharomet2021-09-24 13:08:37
Vue.js
Alexander Sharomet, 2021-09-24 13:08:37

Is it possible to call Vue methods from outside?

Hello.
The button "button" is outside the whole architecture of vue, nothing can be changed in it. The button has an onclick event where the "update()" method is passed.
Is it possible to somehow write the "update ()" method in vue, so that it would be available from outside?

<button type="button" onclick="update()">Test</button> <!-- Вызываем метод update() -->

<div id="app"><!-- Vue --></div>


export default {
  methods: {
    update() { // Можно ли вызвать этот метод из вне?
      console.log('Test')
    }
  }
}


Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-09-24
@sharomet

Can. To do this, you need a reference to the component instance that contains the method you need. For example . This is if the component is the root. If not, then ... well, you can try . Or you can still change your button - cut out the inline handler, and add a new one from inside the .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question