zoukankan      html  css  js  c++  java
  • Vue3 父组件调用子组件的方法

    Vue3 父组件调用子组件的方法


    // 父组件
    
    <template>
        <div>
         父页面 <son-com ref="sonRef"/> <button @click="handleClick">test</button> </div> </template> <script> import { defineComponent, ref, } from 'vue'; export default defineComponent({ setup(){
        const sonRef = ref(null);
          const handleClick = () => {
             tableFilterDemoRef.value.song();
          }
      return { sonRef, handleClick, } 
      }
    })
    </script// 子组件<template>
        <div>
            子页面
        </div>
    </template>
    
    <script>
    import {
      defineComponent
    } from 'vue';
    
    export default defineComponent({
        setup(){
        const song = () => alert('hello world');
        return { 
          song, // 别忘记 return
        }
      }
    })
    </script>

     如果是TS定义可以使用

    const sonRef = ref<null | HTMLElement>(null);

    vue2调用子组件方法

    vue2调用子组件方法

  • 相关阅读:
    bzoj1797
    bzoj1266
    bzoj1497
    bzoj1412
    bzoj3156
    JSOI2014第三轮总结
    bzoj1855
    bzoj1044
    codeforces 371D
    codeforces 371B
  • 原文地址:https://www.cnblogs.com/yuzhongyu/p/14076777.html
Copyright © 2011-2022 走看看