• 组件通信 eventtBus


    平级组件的通信 一个全局发布订阅模式,它是挂载到全局的

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>组件通信 &bus</title>
        <script src="./node_modules/vue/dist/vue.js"></script>
    </head>
    <body>
        <div id="app">
           <children1></children1>
           <children2></children2>
        </div>
    </body>
    <script>
        //发布订阅模式
        //适合简单的数据流
         Vue.prototype.$bus = new Vue();
        Vue.component('children1',{
         template:`<div><span>children1</span></div>`,
         mounted() {
             this.$bus.$on('',(food)=>{
                 console.log(food)
             }) 
         },
       })
       Vue.component('children2',{
         template:`<div><span>children2</span></div>`,
         mounted() {
             this.$bus.$emit('','月饼')
         },
       })
       let  vm = new Vue({
             el:'#app',
       })
       //hello
    </script>
    </html>
  • 相关阅读:
    hdu 3367 Pseudoforest
    hdu 2489 Minimal Ratio Tree
    hdu 4009 Transfer water
    poj 3164 Command Network
    hdu 3926 Hand in Hand
    hdu 3938 Portal
    5-26日(面经总结)
    5-25日
    5-21日|5-22日
    5-13日记录|5-14日
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/11540050.html
Copyright © 2020-2023  润新知