Vue3 調用子組件的方法html
// 父組件 <template> <div>
父頁面 <son-com ref="sonRef"/> <button @click="handleClick">test</button> </div> </template> <script> import { defineComponent, ref, } from 'vue'; export default defineComponent({ const sonRef = ref(null); const handleClick = () => { tableFilterDemoRef.value.song(); } setup(){ return { sonRef, handleClick, } } }) </script>
// 子組件 <template> <div> 子頁面 </div> </template> <script> import { defineComponent } from 'vue'; export default defineComponent({ const song = () => { alert('hellor world'); } setup(){ return { song, // 別忘記 return } } }) </script>
若是是TS定義能夠使用
vue
const sonRef = ref<null | HTMLElement>(null);
vue2調用子組件方法spa
https://www.cnblogs.com/yuzhongyu/p/10825824.htmlcode