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

网站建设的公司哪家便宜wordpress 重定位

网站建设的公司哪家便宜,wordpress 重定位,网络推广建议,百度关键词点击器1.知识点 是一种组件间通信的方式#xff0c;适用于任意组件间通信 2.使用步骤 “消息订阅与发布”可依赖的第三方很多#xff0c;这里使用pubsub-js库 1.安装pubsub#xff1a;npm i pubsub-js 2.引入#xff1a;import pubsub from pubsub-js 3.接收数据#xff1a;A组件…1.知识点 是一种组件间通信的方式适用于任意组件间通信 2.使用步骤 “消息订阅与发布”可依赖的第三方很多这里使用pubsub-js库 1.安装pubsubnpm i pubsub-js 2.引入import pubsub from pubsub-js 3.接收数据A组件想接收数据则在A组件中订阅消息订阅的回调留在A组件中    methods(){      demo(data){......}  }  ...... mounted(){     this.pid pubsub.subscribe(xxx,this.demo)   //订阅消息  } 4.提供数据    pubsub.publish(xxx,数据) 5.最好在beforeDestroy钩子中用pubsub.unsubscribe(pid)取消订阅 问题“全局事件总线”和“消息订阅与发布”都可以实现任意组件间通信那用哪个好 答案推荐使用“全局事件总线”因为它是vue提供的完全使用的vue技术而“消息订阅与发布”则是第三方。 使用语法 消息订阅 语法 import pubsub from pubsub-jsmounted() { this.pubId pubsub.subscribe(hello,(msgName,data){// console.log(有人发布了hello消息hello消息的回调执行了,msgName,data) //msgName为事件名hello data才是接收到的数据 }) }, beforeDestroy() {// this.$bus.$off(hello) pubsub.unsubscribe(this.pubId) //这里注意不是跟全局事件总线一样是hello事件名 }消息发布 语法 import pubsub from pubsub-jspubsub.publish(hello,666)3.注意点 1.取消订阅方式和“全局事件总线”不同取消订阅指定订阅返回的id且每次返回的id都不同而“全局事件总线”指定的是“自定义事件名称” 2.订阅回调配置一定要使用箭头函数或者外部定义方法在订阅中引用也行千万不要使用普通函数因为普通函数中this不指代vc而是undefine这一点跟“全局事件总线”中的注意点很像但还是略有不同 3.消息订阅会接收到2个参数第1个参数为消息名称第2个参数才是传递过来的值如写法1但是实际msgName参数1他跟用不到它所以可使用下划线“_”占个位如写法2 写法一 this.pubId pubsub.subscribe(hello,(msgName,data){// console.log(有人发布了hello消息hello消息的回调执行了,msgName,data) })写法二 this.pubId pubsub.subscribe(hello,(_,data){// console.log(有人发布了hello消息hello消息的回调执行了,_,data) })4.箭头函数中的名称(msgName,data){}可以随便写但是避免使用使用关键字名字 完整代码 Student.vue(发布方) templatediv classstudenth2学生姓名{{name}}/h2h2学生性别{{sex}}/h2button clicksendStudentName把学生名给School组件/button/div /templatescriptimport pubsub from pubsub-jsexport default {name:Student,data() {return {name:张三,sex:男,}},mounted() {// console.log(Student,this.x)},methods: {sendStudentName(){// this.$bus.$emit(hello,this.name)pubsub.publish(hello,666)}},} /scriptstyle langless scoped.student{background-color: pink;padding: 5px;margin-top: 30px;} /styleSchool.vue(订阅方) templatediv classschoolh2学校名称{{name}}/h2h2学校地址{{address}}/h2/div /templatescriptimport pubsub from pubsub-jsexport default {name:School,data() {return {name:尚硅谷,address:北京,}},mounted() {// console.log(School,this)/* this.$bus.$on(hello,(data){console.log(我是School组件收到了数据,data)}) */this.pubId pubsub.subscribe(hello,(msgName,data){console.log(this)console.log(有人发布了hello消息hello消息的回调执行了,msgName,data)})},beforeDestroy() {// this.$bus.$off(hello)pubsub.unsubscribe(this.pubId)},} /scriptstyle scoped.school{background-color: skyblue;padding: 5px;} /style参考文章vue2知识点消息订阅与发布_vue2消息订阅与发布_刘大猫.的博客-CSDN博客
http://www.pierceye.com/news/701373/

相关文章:

  • 网站建设免费的做网站一个人可以吗
  • 网站建设公司价格差别西安网站建设winkuo
  • 途牛网站建设株洲网站优化
  • 网站聊天怎么做网站数据库连接错误
  • 株洲网站优化哪家强网页动态设计
  • 百度是什么网站培训中心网站建设论文
  • 自己做的网站如何管理线上推广是做什么的
  • 关键字挖掘爱站网xampp配置多网站
  • 做社交网站搭建网站的步骤
  • 外围网站做代理关于网站建设需要的研究方法
  • 成都网站建设赢展怎样建设尧都水果网站
  • 网站建设英文文献佛山外贸网站推广
  • wordpress 网站显示ip哪里可以建网站
  • 网站是干嘛用的凡科教育
  • 黄页营销网站南京哪些公司做网站
  • 俄语网站推广工程公司名称大全
  • 怎么知道网站是php什么是网站推广?
  • 温州在线课堂番禺网站建设优化
  • php怎么做网站快大都会app下载最新版本
  • 麻城网站建设公司网络推广公司挣钱吗
  • t型布局网站的样子自己做的网站如何上传
  • 排版设计模板网站百度搜索下载安装
  • 网站页面建设需要ps吗网站建设结单 优帮云
  • 网站建设对我有什么好处网站首页被k 做跳转
  • 美辰网站建设网站建设公司转型做什
  • 创意网站界面怎么查注册公司的名字可不可以用
  • 微友说是做网站维护让帮忙投注中小企业经营管理培训班
  • 网站开发宣传标语虚拟币挖矿网站开发
  • wordpress是否免费网站移动端seo
  • 加盟网站建设服务极简风格 wordpress