Called with $ref
Direct code:
child components:
<template>
<div>
</div>
</template>
<script>
export default {
data(){
return {
num:'123'
}
},
computed: {
},
components : {
'children': children
},
methods:{
childMethod() {
alert('childMethod do...')
}
},
created(){
}
}
</script>
Parent component
Parent component: Add in child component ref can be called through this.$refs.ref.method
<template>
<div @click="parentMethod">
<children ref="c1"></children>
</div>
</template>
<script>
import children from 'components/children/children.vue'
export default {
data(){
return {
}
},
computed: {
},
components: {
'children': children
},
methods:{
parentMethod() {
console.log(this.$refs.c1) //The returned is a vue object, so its method can be called directly this.$refs. c1.childMethod(); Similarly } }, created(){ } } </script>
Vue's methods and properties for parent components to call child components
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326090271&siteId=291194637
Ranking