当前位置: 首页 > news >正文

青岛西海岸新区建设局网站关键词搜索排名公司

青岛西海岸新区建设局网站,关键词搜索排名公司,德阳市建设局网站,黄骅市做网站全局事件总线(GlobalEventBus) 一种可以在任意组件通信的方式,本质上就是一个对象,它必须满足以下条件 所有的组件对象都必须能看见他这个对象必须能够使用$ on $ emit $ off方法取绑定、触发和解绑事件 使用步骤 定义全局事件总线 //创建VUE new V…

全局事件总线(GlobalEventBus)

一种可以在任意组件通信的方式,本质上就是一个对象,它必须满足以下条件

  1. 所有的组件对象都必须能看见他
  2. 这个对象必须能够使用$ on $ emit $ off方法取绑定、触发和解绑事件

使用步骤

  1. 定义全局事件总线
//创建VUE
new Vue({el:'#app',render:h=> h(App),beforeCreate(){Vue.prototype.$bus=this //安装全局事件总线},})
  1. 使用事件总线
    a.接收数据:A组件想接收数据,则在A组件中给$bus 绑定自定义事件,事件的回调留在A组件自身
export default{methods(){demo(data){...}}...mounted(){this.$bus.$on('xxx',this.demo)}
}

b.提供数据:this.$bus.$emit(''xxx,data)
3. 最好在beforeDestroy钩子中,用**$off()**去解绑当前组件所用到的事件。

src/main.js

//引入vue
import Vue from 'vue'
//引入APP.vue
import App from './App.vue'//关闭Vue的生产提示
Vue.config.productionTip=false//创建VUE
new Vue({el:'#app',render:h=> h(App),beforeCreate(){Vue.prototype.$bus=this //安装全局事件总线},})

src/App.vue

<template><div class="app"><h1>{{msg}}</h1><School></School><Student></Student></div>
</template><script>import Student from './components/Student'import School from './components/School'export default {name:'App',components:{School,Student},data() {return {msg:'你好啊!'}}}
</script><style scoped>.app{background-color: gray;padding: 5px;}
</style>

src/compoents/School.vue

<template><div class="school"><h2>学校名称:{{name}}</h2><h2>学校地址:{{address}}</h2></div>
</template><script>export default {name:'School',data() {return {name:'尚硅谷',address:'北京',}},mounted() {// console.log('School',this)this.$bus.$on('hello',(data)=>{console.log('我是School组件,收到了数据',data)})},beforeDestroy() {this.$bus.$off('hello')},}
</script><style scoped>.school{background-color: skyblue;padding: 5px;}
</style>

src/compoents/Student.vue

<template><div class="student"><h2>学生姓名:{{name}}</h2><h2>学生性别:{{sex}}</h2><button @click="sendStudentName">把学生名给School组件</button></div>
</template><script>export default {name:'Student',data() {return {name:'张三',sex:'男'}},mounted() {// console.log('Student',this.x)},methods: {sendStudentName(){this.$bus.$emit('hello',this.name)}},}
</script><style  scoped>.student{background-color: pink;padding: 5px;margin-top: 30px;}
</style>

在这里插入图片描述

http://www.mmbaike.com/news/67027.html

相关文章:

  • 个人网站建设的论文手机管家一键优化
  • wordpress导入excel建站seo是什么
  • 珠海公司网站制作qq群推广平台
  • 网站的设计流程是怎么样的?网络营销策略是什么
  • 英文b2c网站建设百度seo公司哪家最好
  • win7用自己ip做网站seo课程培训视频
  • 个人可以做慈善网站吗长沙seo网络优化
  • 网站定制设计网页价格多少钱网站免费网站免费
  • 企业网站管理系统湖南岚鸿网页设计模板网站免费
  • 厦门网站建设合同线下推广有哪几种渠道
  • wordpress 站群注意无锡优化网站排名
  • 做网站建设怎么跑客户百度广告电话号码
  • 电脑怎么做网站中国建设网官方网站
  • 做旅游网站赚钱吗如何优化网络环境
  • 如何分析网站流量网络推广的渠道
  • 宠物网站制作内容昆明seo案例
  • wordpress 调用站外api百度seo刷排名网址
  • wordpress如何加入视频播放器沙洋县seo优化排名价格
  • 广州建筑集团下属公司有哪些网站seo
  • 做网站的公司风险大不大谷歌关键词搜索工具
  • 越南美女做美食视频网站百度竞价登录入口
  • 佛山做网站需要多少钱网站注册搜索引擎的目的是
  • 石家庄关键词排名软件宁波seo怎么做引流推广
  • 一级a做爰片2017免费网站网页模版
  • 展示型网站举例专业软文发布平台
  • 旅游网站制作 价格seo哪家强
  • 酒泉网站建设东莞全网营销推广
  • 浙江公司网站建设推广百度seo自然优化
  • 个体户网站建设茶叶网络推广方案
  • 神华集团两学一做网站东莞好的网站国外站建设价格