Законно ли вызывать методы дочерних компонентов через $ref?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
<my-component ref="myComponent"></my-component>
<button @click="handleToggle">toggle</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.1/vue.min.js"></script>
<script>
Vue.component('my-component', {
template: '<div v-if="active">my-component</div>',
data: () => ({ active: false }),
methods: {
toggle() {
this.active = !this.active
}
}
})
new Vue({
el: '#app',
methods: {
handleToggle() {
this.$refs.myComponent.toggle() // я об этом
}
}
})
</script>
</body>
</html>