zoukankan      html  css  js  c++  java
  • vue.js组件之间通讯--父组件调用子组件的一些方法,子组件暴露一些方法,让父组件调用

    
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>
    <div id="app"></div>
    </body>
    <script src="node_modules/vue/dist/vue.js"></script>
    <script>
    //父亲调用子组件的方法,子组件暴露一些方法让父组件调用
    // ref如果写在dom上,表示获取dom,如果写在组件上,表示当前组件的实例
    let vm=new Vue({
    el:"#app",
    template:'<child ref="c"></child>',
    //一定要放在mounted下面,因为mounted方法表示数据和视图渲染完成,
    mounted(){
    //当前的ref指向的是child组件的实例,通过实例调用下面的fn方法
    this.$refs.c.fn();
    },
    components:{
    child:{
    template:'<div>child</div>',
    methods:{
    fn(){
    alert("子子")
    }
    }
    }
    }
    })
    </script>
    </html>
     
  • 相关阅读:
    Vulkan
    C# Optimization
    C# Bridge Pattern(Handle/Body)
    Favorite Games
    Unity Particle System Sorting Order
    UGUI
    C# Language Specification
    接口的显式实现和隐式实现
    C#反射机制
    wcf 使用sqlMembership证书认证
  • 原文地址:https://www.cnblogs.com/null11/p/7479189.html
Copyright © 2011-2022 走看看