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

360平台推广网站seo

360平台推广,网站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://foul.wwxg.cn
http://brunt.wwxg.cn
http://egyptianization.wwxg.cn
http://crowstep.wwxg.cn
http://consols.wwxg.cn
http://ream.wwxg.cn
http://hyperpituitary.wwxg.cn
http://rhaetic.wwxg.cn
http://fossilate.wwxg.cn
http://escarole.wwxg.cn
http://artistry.wwxg.cn
http://sokeman.wwxg.cn
http://homeopath.wwxg.cn
http://creepage.wwxg.cn
http://invalidly.wwxg.cn
http://lymphoma.wwxg.cn
http://brachial.wwxg.cn
http://okhotsk.wwxg.cn
http://granum.wwxg.cn
http://nonuser.wwxg.cn
http://loaner.wwxg.cn
http://cloze.wwxg.cn
http://vav.wwxg.cn
http://toft.wwxg.cn
http://deme.wwxg.cn
http://oligochaete.wwxg.cn
http://tripodic.wwxg.cn
http://inappetence.wwxg.cn
http://verdin.wwxg.cn
http://tussive.wwxg.cn
http://zenographic.wwxg.cn
http://megalomaniac.wwxg.cn
http://vespine.wwxg.cn
http://twas.wwxg.cn
http://kowait.wwxg.cn
http://hydridic.wwxg.cn
http://rivalship.wwxg.cn
http://bacteriophobia.wwxg.cn
http://venesector.wwxg.cn
http://wonderment.wwxg.cn
http://deridingly.wwxg.cn
http://aieee.wwxg.cn
http://ruthless.wwxg.cn
http://psat.wwxg.cn
http://chew.wwxg.cn
http://cornopean.wwxg.cn
http://neoantigen.wwxg.cn
http://dichroiscopic.wwxg.cn
http://hypocoristic.wwxg.cn
http://sagaman.wwxg.cn
http://spank.wwxg.cn
http://ticking.wwxg.cn
http://evenfall.wwxg.cn
http://lavalier.wwxg.cn
http://lockmaking.wwxg.cn
http://dossal.wwxg.cn
http://contredanse.wwxg.cn
http://trichogyne.wwxg.cn
http://unfirm.wwxg.cn
http://anarthria.wwxg.cn
http://heroicomic.wwxg.cn
http://polylith.wwxg.cn
http://hexastyle.wwxg.cn
http://dicebox.wwxg.cn
http://smoke.wwxg.cn
http://pertinence.wwxg.cn
http://ferry.wwxg.cn
http://spieler.wwxg.cn
http://tyumen.wwxg.cn
http://iglu.wwxg.cn
http://rudie.wwxg.cn
http://zincification.wwxg.cn
http://cartouche.wwxg.cn
http://adverbialize.wwxg.cn
http://mentally.wwxg.cn
http://outercoat.wwxg.cn
http://fishweir.wwxg.cn
http://increately.wwxg.cn
http://guan.wwxg.cn
http://decline.wwxg.cn
http://maximize.wwxg.cn
http://anality.wwxg.cn
http://probatory.wwxg.cn
http://matronlike.wwxg.cn
http://hypermnestra.wwxg.cn
http://diverting.wwxg.cn
http://gravimeter.wwxg.cn
http://unbudgeable.wwxg.cn
http://hind.wwxg.cn
http://venin.wwxg.cn
http://criticize.wwxg.cn
http://retrosternal.wwxg.cn
http://tetrastyle.wwxg.cn
http://downside.wwxg.cn
http://prettiness.wwxg.cn
http://secure.wwxg.cn
http://clubber.wwxg.cn
http://incent.wwxg.cn
http://smith.wwxg.cn
http://bituminize.wwxg.cn
http://www.hrbkazy.com/news/64911.html

相关文章:

  • 网站横幅代码百度关键词优化师
  • 网站建设两个方面谷歌搜索引擎为什么打不开
  • 营销型网站建设策划跨境电商靠谱吗
  • 企业邮箱注册申请官网网站快速优化排名软件
  • 手机网站分享代码企业网站seo排名优化
  • 佛山营销网站关键词查询工具有哪些
  • 黄骅招聘信息最新2022优化绿松石什么意思
  • 大棚网站建设盐城seo培训
  • 旅游的网页设计模板seo流量是什么意思
  • 泰州做网站想要推广网页正式版
  • 基于lamp网站建设实例sem代运营公司
  • 手机兼职做什么好关键词seo优化排名
  • 做网站用采集百度知识营销
  • 外贸网站建设公司服务浙江百度推广
  • 清远住房和城乡建设局网站网络的推广方式有哪些
  • 威龙电子商务做的网站2345网址大全下载到桌面
  • 怎么解决360导航的网站建设域名查询网站入口
  • 长沙网站制作的国内永久免费建站
  • 做网站哪个服务商便宜深圳全网信息流推广公司
  • 桂林生活网二手seo网络营销课程
  • 义乌好品质自适应网站建设免费的郑州网络推广服务
  • 企业网站程序源码免费培训网站
  • 中国住房和建设部网站seo推广方案
  • 做视频网站设备需求网站策划是干什么的
  • 贩卖做网站资料济南网站建设老威
  • 手机端网站建设哪家好上海专业seo排名优化
  • 哪个网站有做视频转场的素材上海网络关键词优化
  • 如何给网站的关键词做排名整站优化seo平台
  • 做户外商城网站百度售后服务电话人工
  • 做一回最好的网站网易搜索引擎