zoukankan      html  css  js  c++  java
  • 父组件调用子组件中的方法- this.$refs.xxx.子组件方法();

    子组件中有一个说的方法 在父组件中去调用
    当你点击的时候 去调用子组件中的方法

    fu.vue
    在父组件的方法中调用子组件的方法,
    很重要 this.$refs.mychild.parentHandleclick();

    {
        <template>
        <div>
            <button @click="clickParent">点击 调用子组件</button>
            <child ref="mychild"></child>
        </div>
        </template>
        
        <script>
        import Child from "../zi/zi";
        export default {
        components: {
            child: Child  //key:value key是组件名称  value是被引入时的名称
        },
        methods: {
            clickParent() {
            this.$refs.mychild.parentHandleclick();
            }
        }
        };
        </script>
     
    }

    zi.vue

    {
        <template>
          <div ref="col">child</div>
        </template>
        
        <script>
            export default {
                methods: {
                    parentHandleclick(e) {
                    console.log("我是子组件在说")
                    }
                }
            };
        </script>
    }
  • 相关阅读:
    APPlication,Session和Cookie的区别
    C# 中的Request对象的应用
    从字符串里提取一个列表(数组)
    UDP:用户数据报协议
    反射
    网络编程
    多线程
    final,finally和finalize的区别
    集合
    StringBuffer
  • 原文地址:https://www.cnblogs.com/IwishIcould/p/11306344.html
Copyright © 2011-2022 走看看