Open a Vuetify dialog from a component template in VueJS

前端 未结 8 1425
故里飘歌
故里飘歌 2020-12-02 11:27

I\'m using the VueJS Vuetify framework and I need to open a dialog - that gets imported as a component template - from another template. Once the Menu butto

8条回答
  •  生来不讨喜
    2020-12-02 11:54

    No event bus needed and v-model

    Update:

    When I first answered this, I posted my answer as a "workaround", since it didn't felt completely "right" at the time and I was new to Vue.js. I wanted to open or close the dialog by using a v-model directive, but I couldn't get there. After a time I found how to do this in the docs, using the input event and the value property, and here's how I think it should be done without an event bus.

    Parent component:

    
    
    
    

    Child component (ScheduleForm):

    
    
    
    

    Original answer:

    I was able to work around this without the need for a global event bus.

    I used a computed property with a getter AND a setter. Since Vue warns you about mutating the parent property directly, in the setter I simply emitted an event to the parent.

    Here's the code:

    Parent component:

    
    
    
    

    Child component (ScheduleForm):

    
    
    
    

提交回复
热议问题