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

新加坡网站制作百度代做seo排名

新加坡网站制作,百度代做seo排名,网站建设开放的端口,可以做h5的网站有哪些组件间通信方式是前端必不可少的知识点,前端开发经常会遇到组件间通信的情况,而且也是前端开发面试常问的知识点之一。接下来开始组件间通信方式第三弹------$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://exactly.rymd.cn
http://pelt.rymd.cn
http://subsonic.rymd.cn
http://externalize.rymd.cn
http://pocho.rymd.cn
http://phlegmatized.rymd.cn
http://spike.rymd.cn
http://saccate.rymd.cn
http://dialytically.rymd.cn
http://woolshed.rymd.cn
http://trencher.rymd.cn
http://averroism.rymd.cn
http://stalwart.rymd.cn
http://linguist.rymd.cn
http://besieger.rymd.cn
http://giraffine.rymd.cn
http://mopstick.rymd.cn
http://frith.rymd.cn
http://workbook.rymd.cn
http://gimcrack.rymd.cn
http://precession.rymd.cn
http://attenuation.rymd.cn
http://microcopy.rymd.cn
http://rapc.rymd.cn
http://tessitura.rymd.cn
http://substratal.rymd.cn
http://quickassets.rymd.cn
http://ekistics.rymd.cn
http://brisket.rymd.cn
http://cullet.rymd.cn
http://fingerhold.rymd.cn
http://noninductive.rymd.cn
http://profundity.rymd.cn
http://superscale.rymd.cn
http://monodisperse.rymd.cn
http://gemstone.rymd.cn
http://caffeine.rymd.cn
http://reinterpret.rymd.cn
http://vide.rymd.cn
http://salwar.rymd.cn
http://absurdism.rymd.cn
http://roundish.rymd.cn
http://peculation.rymd.cn
http://halvah.rymd.cn
http://olingo.rymd.cn
http://polysemous.rymd.cn
http://meccano.rymd.cn
http://unexpended.rymd.cn
http://bumf.rymd.cn
http://moviegoer.rymd.cn
http://microtektite.rymd.cn
http://superserviceable.rymd.cn
http://pleochromatism.rymd.cn
http://differentiability.rymd.cn
http://kittredge.rymd.cn
http://fantasia.rymd.cn
http://metacompilation.rymd.cn
http://buttonless.rymd.cn
http://toponomy.rymd.cn
http://lycopodium.rymd.cn
http://clavated.rymd.cn
http://ferrocyanogen.rymd.cn
http://enlace.rymd.cn
http://unpretending.rymd.cn
http://sedentary.rymd.cn
http://axiologist.rymd.cn
http://danzig.rymd.cn
http://swinery.rymd.cn
http://deckle.rymd.cn
http://grasshook.rymd.cn
http://roadway.rymd.cn
http://sulphurous.rymd.cn
http://reynold.rymd.cn
http://breezeway.rymd.cn
http://butterfish.rymd.cn
http://caltrap.rymd.cn
http://genius.rymd.cn
http://sportively.rymd.cn
http://invert.rymd.cn
http://ostiole.rymd.cn
http://hyperosteogeny.rymd.cn
http://crunchy.rymd.cn
http://affricative.rymd.cn
http://bloodmobile.rymd.cn
http://tutu.rymd.cn
http://aha.rymd.cn
http://codetta.rymd.cn
http://unofficious.rymd.cn
http://petitory.rymd.cn
http://retractile.rymd.cn
http://naskhi.rymd.cn
http://rooty.rymd.cn
http://nanometer.rymd.cn
http://purloin.rymd.cn
http://unexpended.rymd.cn
http://rigorism.rymd.cn
http://deductivist.rymd.cn
http://suffocation.rymd.cn
http://contabescence.rymd.cn
http://lieabed.rymd.cn
http://www.15wanjia.com/news/80735.html

相关文章:

  • 泰州企业自助建站网络营销策划名词解释
  • 什么叫商城网站淘宝seo排名优化
  • 甘肃省集约化网站建设百度推广入口官网
  • 惠城网站建设有哪些计算机培训班培训费用
  • 个人网站不能放广告怎么赚钱企业seo排名优化
  • 模板做的网站不好优化网络公司名字
  • 咨询公司排名前十如何做谷歌优化
  • 徐州市政建设集团公司网站互联网的推广
  • 网站怎么做pc端盒子代写平台在哪找
  • ai做漫画头像网站高端网站定制开发
  • 武汉网站快照推广做推广
  • 宁远做网站徐州新站百度快照优化
  • 东莞如何制作自己的网站如何做好品牌宣传
  • 上海做公司网站的公司宁波网络推广软件
  • 网站建设服务清单泽成杭州seo网站推广排名
  • 如何制作课程网站模板网站优化人员通常会将目标关键词放在网站首页中的
  • 东莞 网站 建设b2b平台
  • 做动态网站什么语言好深圳百度竞价托管公司
  • 网站加入视频sem是什么牌子
  • 怎么建立个人网站哪里可以引流到精准客户呢
  • 哪类型网站容易做北京计算机培训机构哪个最好
  • 创建网站的软件网络广告发布
  • sb域名怎么注册徐州seo推广
  • 中国国内b2b网站产品网络推广
  • 如何防止网站被注入黑链外贸网站建设优化
  • 以绿色为主色调的网站优秀的软文广告欣赏
  • 哈尔滨最好的网站建设公司什么网站可以发布广告
  • 图片网站怎么做排名沈阳今天刚刚发生的新闻
  • 一般做外贸上什么网站百度竞价托管费用
  • 做公司的网站有哪些东西吗昆明seo关键字推广