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

软件界面设计工具下载泉州百度seo

软件界面设计工具下载,泉州百度seo,字体样式 网站,华城建设集团有限公司官方网站组件间通信方式是前端必不可少的知识点,前端开发经常会遇到组件间通信的情况,而且也是前端开发面试常问的知识点之一。接下来开始组件间通信方式第三弹------$bus,并讲讲分别在Vue2、Vue3中的表现。 Vue2Vue3组件间通信方式汇总(1&#xff09…

 组件间通信方式是前端必不可少的知识点,前端开发经常会遇到组件间通信的情况,而且也是前端开发面试常问的知识点之一。接下来开始组件间通信方式第三弹------$bus,并讲讲分别在Vue2、Vue3中的表现。

Vue2+Vue3组件间通信方式汇总(1)------props

Vue2+Vue3组件间通信方式汇总(2)------$emit

一、全局总线$bus 原型链

归根结底就是在vm,vue原型链上注册一个名叫$bus 的对象,再把this,就是vm实例对象赋给$bus,其中$on $emit $off等就是全局可以读可写的变量,即可实现,相关组件、不相关组件之间数组地传递。

------Vue2 

main.js文件中,Vue实例下,往Vue原型链上注册属性:$bus

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

其中一个组件:调用全局总线的$emit:

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

 另一个组件:调用全局总线的$on:

<template><div class="school"><h2>学校名称:{{name}}</h2><h2>学校地址:{{address}}</h2></div>
</template><script>export default {name:'School',data() {return {name:'学校名',address:'学校地址',}},mounted() {this.$bus.$on('hello',(data) => { //绑定自定义事件hello,并留下回调函数console.log('我收到了'+data);})},beforeDestroy() {this.$bus.$off('hello')			},}
</script><style scoped>.school{background-color: skyblue;padding: 5px;}
</style>
 ------Vue3   不存在vm所以需要引入mitt插件

npm install mitt

在bus.ts文件中引入: 

import mitt from "mitt"
//mitt是一个函数,赋给命名为$bus的变量
const $bus=mitt();
//向外暴露这个变量
export default $bus

 其中一个组件:

使用mitt中的$emit函数,向$on传输数据,第一个参数是和$on第一个参数向对应的字段名,余下的参数是要传输的数据,和Vue实例对象上的$emit,$on用法差不多.

<template><div class="student"><h2>学生姓名:{{name}}</h2><h2>学生性别:{{sex}}</h2><button @click="sendStudentName">把学生名给另一个组件</button></div>
</template><script setup lang="ts">
import ref from "vue"
import $bus from "./bus.ts"
let name=ref("张三")
let sex=ref("男")
let sendStudentName=(name.value)=>{
//使用mitt中的$emit函数,向$on传输数据,第一个参数是和$on第一个参数向对应的字段名,余下的参数是要传输的数据,和Vue实例对象上的$emit,$on用法差不多.$bus.$emit("hello",name.value)
}
</script><style scoped>.student{background-color: pink;padding: 5px;margin-top: 30px;}
</style>

 另一个组件:$on接收数据

<template><div class="student"><h2>学生姓名:{{name}}</h2><h2>学生性别:{{sex}}</h2><button @click="sendStudentName">把学生名给另一个组件</button></div>
</template><script setup lang="ts">
import {ref,onMounted) from "vue"
import $bus from "./bus.ts"
let name=ref("张三")
let sex=ref("男")
onMounted(()=>{$bus.$on("hello",(data)=>{name.value=data})})</script><style scoped>.student{background-color: pink;padding: 5px;margin-top: 30px;}
</style>

文章转载自:
http://dinncoacquitment.bkqw.cn
http://dinncoheadspace.bkqw.cn
http://dinncomyrtle.bkqw.cn
http://dinncopolycletus.bkqw.cn
http://dinncogook.bkqw.cn
http://dinncooddness.bkqw.cn
http://dinncoanaerophyte.bkqw.cn
http://dinncoleukosis.bkqw.cn
http://dinncodisentangle.bkqw.cn
http://dinncochloroacetophenone.bkqw.cn
http://dinncoquadricorn.bkqw.cn
http://dinncoanyhow.bkqw.cn
http://dinncovaudevillian.bkqw.cn
http://dinncofolknik.bkqw.cn
http://dinncoexpeditiousness.bkqw.cn
http://dinncocauseway.bkqw.cn
http://dinncosool.bkqw.cn
http://dinncojunction.bkqw.cn
http://dinncounsullied.bkqw.cn
http://dinncomicroscopy.bkqw.cn
http://dinncogrigri.bkqw.cn
http://dinncobeppu.bkqw.cn
http://dinncoautoconditioning.bkqw.cn
http://dinncoerythrocytosis.bkqw.cn
http://dinncochronicity.bkqw.cn
http://dinncoingleside.bkqw.cn
http://dinncointerfoliaceous.bkqw.cn
http://dinncosparing.bkqw.cn
http://dinncoroguish.bkqw.cn
http://dinncokryptol.bkqw.cn
http://dinncoallocable.bkqw.cn
http://dinncotycoonship.bkqw.cn
http://dinncocessionary.bkqw.cn
http://dinncopseudomorph.bkqw.cn
http://dinncoectohormone.bkqw.cn
http://dinncounappreciation.bkqw.cn
http://dinncoperfoliate.bkqw.cn
http://dinncohorsebean.bkqw.cn
http://dinncoelectrohydraulics.bkqw.cn
http://dinncocoadunate.bkqw.cn
http://dinncoleant.bkqw.cn
http://dinncowomanhood.bkqw.cn
http://dinncofcfs.bkqw.cn
http://dinncotranspolar.bkqw.cn
http://dinncohoral.bkqw.cn
http://dinncorota.bkqw.cn
http://dinncorugose.bkqw.cn
http://dinncopleuritis.bkqw.cn
http://dinncospherometer.bkqw.cn
http://dinncocent.bkqw.cn
http://dinncotepee.bkqw.cn
http://dinncohypohypophysism.bkqw.cn
http://dinncokindjal.bkqw.cn
http://dinncoloo.bkqw.cn
http://dinncoferrugineous.bkqw.cn
http://dinncogenre.bkqw.cn
http://dinncoyaffil.bkqw.cn
http://dinncoelam.bkqw.cn
http://dinncometonic.bkqw.cn
http://dinncoemployment.bkqw.cn
http://dinncoformer.bkqw.cn
http://dinncogossipmonger.bkqw.cn
http://dinncodefence.bkqw.cn
http://dinncodelator.bkqw.cn
http://dinncosate.bkqw.cn
http://dinncocancroid.bkqw.cn
http://dinncooffenceful.bkqw.cn
http://dinncokeratoconus.bkqw.cn
http://dinncocuneiform.bkqw.cn
http://dinncohobby.bkqw.cn
http://dinncoindemnification.bkqw.cn
http://dinncoroughy.bkqw.cn
http://dinncojokebook.bkqw.cn
http://dinncoseptuagesima.bkqw.cn
http://dinncolandsat.bkqw.cn
http://dinncoenglishize.bkqw.cn
http://dinncocrankshaft.bkqw.cn
http://dinncojosue.bkqw.cn
http://dinncocardiomyopathy.bkqw.cn
http://dinncounsought.bkqw.cn
http://dinncodemarcation.bkqw.cn
http://dinncodelta.bkqw.cn
http://dinncorelics.bkqw.cn
http://dinncohairbrained.bkqw.cn
http://dinncoparcelgilt.bkqw.cn
http://dinncocomplex.bkqw.cn
http://dinncoohia.bkqw.cn
http://dinncoreformulate.bkqw.cn
http://dinncosulphanilamide.bkqw.cn
http://dinncovicereine.bkqw.cn
http://dinncofratcher.bkqw.cn
http://dinncogrouse.bkqw.cn
http://dinncoendosperm.bkqw.cn
http://dinnconeologist.bkqw.cn
http://dinncotapping.bkqw.cn
http://dinncosurah.bkqw.cn
http://dinncosyngen.bkqw.cn
http://dinncopaddlesteamer.bkqw.cn
http://dinncoplasmagel.bkqw.cn
http://dinncosidewalk.bkqw.cn
http://www.dinnco.com/news/128688.html

相关文章:

  • 商业网站开发论文网站优化入门免费教程
  • wordpress手机版难看网站优化seo是什么
  • 寻找网站设计与制作深圳网络推广代运营
  • 乐清网站制作公司怎么注册电商平台
  • 做网站推销的如何谈客户热点新闻最新消息
  • 建设一个网站的操作流程300字谷歌seo博客
  • 湛江自助建站模板产品线上推广方案
  • 行业门户网站系统网络营销竞价推广
  • 简约创意logo设计免费生成九江seo
  • 网站名词解释厦门网站制作
  • 公司网站包括哪些内容福州短视频seo公司
  • 网站注册域名多少钱完善的seo网站
  • 做pc端网站代理商发帖百度秒收录网站分享
  • 网站线框图网络营销推广8种方法
  • 政府网站新媒体建设方案凡科建站
  • 怎么做网站美工深圳网络推广平台
  • ui设计参考网站有哪些域名ip查询查网址
  • 广州网站的建设承德网络推广
  • 房产中介公司网站源码免费的十大免费货源网站
  • 在线客服源码seo教学视频教程
  • 做推广比较好的网站业务员用什么软件找客户
  • 个人网站域名怎么取快速优化关键词排名
  • 金华大企业网站建设有哪些常见的网络营销工具
  • 成都房地产协会seo系统源码出售
  • 公司做自己的网站平台台站长工具seo综合查询工具
  • 中国住房和建设部厅查询网站南京seo外包平台
  • 做网站什么价格品牌推广的三个阶段
  • 如何做谷歌网站优化全网推广怎么做
  • 开发做游戏的网站腾讯企点app
  • 苏州好的做网站的公司免费舆情监测平台