通過
this.$parent
調用父組件中的方法。
父組件
<template>
<div>
<child></child>
</div>
</template>
<script>
import child from '~/components/dam/child';
export default {
components: {
child
},
methods: {
fatherMethod() {
console.log('測試');
}
}
};
</script>
子組件
<template>
<div>
<button @click="childMethod()">點擊</button>
</div>
</template>
<script>
export default {
methods: {
childMethod() {
this.$parent.fatherMethod();
}
}
};
</script>
這樣,父組件中的fatherMethod
就可以被調用了。