I
I
Igor Bezlepkin2019-01-22 09:29:59
Vue.js
Igor Bezlepkin, 2019-01-22 09:29:59

How to call a component with a template from a method?

Hey! How is it possible, when calling a method in a component, to display its template?
For example, we want to make an alert or confirm window, and in order not to embed modals in the template block every time, but simply call methods and this.dialog.confirm () component appeared

methods: {
  confirm () {
    this.dialog.confirm().then(() => {
      console.log('ok')
    }, () => {
      console.log('cancel')
    }
  })
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-01-22
@Bezlepkin

You manually create an instance, manually add $el to the DOM tree, and manually delete it in the same way.
Alert , for example. And here is confirm .

I
in some, 2019-01-24
@iGanza

Implementation of the advice above in the popular ui framework https://github.com/ElemeFE/element/blob/dev/packag...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question