2017-01-04 110 views
2
<div> 
    <button @click="$refs.cart.open()">open</button> 
    <drawer></drawer> 
</div> 

ref = cart is <drawer>,我可以从那个按钮拨打电话吗?怎么样?

--- ---编辑

enter image description here

---编辑与vuex解决---

根模板

toggle() { 
    this.$store.dispatch('toggle', { 
     toggle: 'close' 
    }).then(() => { 
     this.$store.dispatch('toggle', { 
     toggle: 'open' 
     }) 
    }) 
    } 

内抽屉

computed: { 
    toggle() { 
    return this.$store.state.toggle 
    } 
}, 
watch: { 
    toggle(val) { 
    if (val == 'open') this.$refs.cart.open() 
    } 
} 
+0

多一点的代码会有所帮助。 – Saurabh

+0

@saurabh好的编辑,我用QuasarFramework –

回答

2

一个简单的解决方案(不是最好的),是只使用Vue的事件总线这里组件之间的通信。 Quasar有一个全球性的事件总线(http://quasar-framework.org/api/js-events.html)。

最好的解决办法是使用Vuex当然的,但是,没有如果你需要它只是为了这个。

Vue的引用是棘手的,并不总是随时使用。解释很长,并且与Vue如何呈现有关。

+0

我还是不明白,实现事件总线上的情况下,上述情况,请u能帮助打开我的脑海里有一个例子吗?谢谢。 –

+0

我解决它与vuex,我这样做对吗?谢谢。 –