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

佛山市城乡住房建设局网站成人职业技能培训有哪些项目

佛山市城乡住房建设局网站,成人职业技能培训有哪些项目,对整个网站做词频分析,百度站长如何添加网站前言 组件间传值的章节我们知道父组件给子组件传值的时候,使用v-bind的方式定义一个属性传值,子组件根据这个属性名去接收父组件的值,但是假如子组件想给父组件一些反馈呢?就不能使用这种方式来,而是使用事件的方式&a…

前言

组件间传值的章节我们知道父组件给子组件传值的时候,使用v-bind的方式定义一个属性传值,子组件根据这个属性名去接收父组件的值,但是假如子组件想给父组件一些反馈呢?就不能使用这种方式来,而是使用事件的方式,父组件通过注册这个事件的监听来接收子组件的信息,然后做对应的操作。

示例解析

在前面的章节我们使用父组件传递过来的值做一个计数组件的时候,使用v-bind的方式传值,这个时候父子组件间是单向数据流的方式,即子组件无法修改父组件传来的值,所以做计数器组件的时候,子组件只能是拷贝一份父组件传来的值,然后做计数操作,本章我们提供事件的方式实现计数的功能,思想就是,我们修改不了父组件传递过来的值,我们就可以通过事件通知父组件修改这个值:代码如下

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>父子组件通过事件进行通信</title><script src="https://unpkg.com/vue@next"></script>
</head>
<body><div id="root"></div></body>
<script>const app = Vue.createApp({data() {return {count:1}},methods:{handleAddOne(){this.count += 1;}},template: `<div><counter :count = "count" @add-one="handleAddOne" /></div>`});app.component('counter',{props:['count'],emits:{addOne:(count) =>{if(count > 3){alert(count);return true;}return false;}},methods: {handleItemClick(){this.$emit('addOne',this.count);}},template:`<div @click="handleItemClick">{{count}}</div>`});const vm = app.mount('#root');
</script>
</html>

当我们点击显示数字的div时,会执行执行handleItemClick方法,向父组件传递一个add-one事件,并且将目前的count值当成参数传递给父组件,父组件通过@add-one="handleAddOne"监听add-one事件,当收到这个事件后,就执行handleAddOne方法,让count的值加一,然后由于时count的值和子组件又是绑定的,所以这个值也会同步给子组件,这样就会在子组件显示count+1的值。

注意:监听事件,使用“-” 分隔符:如本例中的:@add-one,向外部发送一个事件时用驼峰命名:如本例中的:this.$emit('addOne',this.count);

从代码中我们可以看到从子组件向父组件传递一个事件使用的是$emit()方法,这个方法可以单独传事件如:this.$emit('addOne'); 也可以带参数传递:this.$emit('addOne',2);

另外本例中,我们可以看到这样一段代码:

   emits:{addOne:(count) =>{if(count > 3){alert(count);return true;}return false;}},

其实这里是便于让代码的阅读者能通过emmits关键字快速知道本组件会向外传递哪些事件,毕竟组件多了后,会有一堆事件,在代码中一个个看的确比较费劲,这个模块还有一个功能就是校验我们可以在里面判断父组件传递过来的值,然后做些想做的操作

总结

本文主要介绍父组件和子组件之间的通信,父组件可以通过v-bind的方式将值传递给子组件,子组件可以使用props:[]接收,然后子组件可以通过事件$emit()通知父组件,自己想做的事情,父组件通过@事件名称的方式接收子组件的事件,这里需要注意的是,子组件发送事件时,使用的是驼峰命名,父组件定义监听时使用的是分隔符的方式命名,如此就完成了父子组件的通信。


文章转载自:
http://dinncopreclinical.bkqw.cn
http://dinncodevice.bkqw.cn
http://dinncoholden.bkqw.cn
http://dinncohack.bkqw.cn
http://dinncoargentic.bkqw.cn
http://dinncochop.bkqw.cn
http://dinncogirlhood.bkqw.cn
http://dinncocartogram.bkqw.cn
http://dinncoendocardium.bkqw.cn
http://dinncoallnighter.bkqw.cn
http://dinncobaykal.bkqw.cn
http://dinncosulphidic.bkqw.cn
http://dinncohemoglobinuria.bkqw.cn
http://dinncocantilever.bkqw.cn
http://dinncogarioa.bkqw.cn
http://dinncocatface.bkqw.cn
http://dinncouncircumcision.bkqw.cn
http://dinncohomoeopathist.bkqw.cn
http://dinncogallabiya.bkqw.cn
http://dinncotheophoric.bkqw.cn
http://dinncoallotropy.bkqw.cn
http://dinncocordotomy.bkqw.cn
http://dinncogaba.bkqw.cn
http://dinncokhalifat.bkqw.cn
http://dinncosatrangi.bkqw.cn
http://dinncoplateau.bkqw.cn
http://dinncoflicflac.bkqw.cn
http://dinncogenoa.bkqw.cn
http://dinncojerky.bkqw.cn
http://dinncotalkie.bkqw.cn
http://dinncojoshua.bkqw.cn
http://dinncogossipist.bkqw.cn
http://dinncohowdy.bkqw.cn
http://dinncorosenthal.bkqw.cn
http://dinncoapomictic.bkqw.cn
http://dinncoevanesce.bkqw.cn
http://dinncocoloration.bkqw.cn
http://dinncochangeroom.bkqw.cn
http://dinncofoliar.bkqw.cn
http://dinncopensively.bkqw.cn
http://dinnconaca.bkqw.cn
http://dinncoorgie.bkqw.cn
http://dinncoacropolis.bkqw.cn
http://dinncointerestingly.bkqw.cn
http://dinncooverdiligent.bkqw.cn
http://dinncoeschscholtzia.bkqw.cn
http://dinncounrelaxing.bkqw.cn
http://dinncotsushima.bkqw.cn
http://dinncoalumnus.bkqw.cn
http://dinncosoapie.bkqw.cn
http://dinncobeethovenian.bkqw.cn
http://dinncorelay.bkqw.cn
http://dinncotheobromine.bkqw.cn
http://dinncolang.bkqw.cn
http://dinncoconcentration.bkqw.cn
http://dinncosodden.bkqw.cn
http://dinncomycobacterium.bkqw.cn
http://dinncorococo.bkqw.cn
http://dinncogiga.bkqw.cn
http://dinncogenerable.bkqw.cn
http://dinncotref.bkqw.cn
http://dinncorestaurant.bkqw.cn
http://dinncoauthorless.bkqw.cn
http://dinncolymphangiography.bkqw.cn
http://dinncoquarrelsome.bkqw.cn
http://dinncopelycosaur.bkqw.cn
http://dinncoserpentine.bkqw.cn
http://dinncoisoproterenol.bkqw.cn
http://dinnconontraditional.bkqw.cn
http://dinncoelaterite.bkqw.cn
http://dinncovoluntary.bkqw.cn
http://dinncohumungous.bkqw.cn
http://dinncoiconoclast.bkqw.cn
http://dinncomarmolite.bkqw.cn
http://dinncoseamanly.bkqw.cn
http://dinncoplanner.bkqw.cn
http://dinncointrospect.bkqw.cn
http://dinncobarbican.bkqw.cn
http://dinncogeneralise.bkqw.cn
http://dinncofracture.bkqw.cn
http://dinncoplumbless.bkqw.cn
http://dinncowirra.bkqw.cn
http://dinncoammino.bkqw.cn
http://dinncoasosan.bkqw.cn
http://dinncosubfebrile.bkqw.cn
http://dinncomadrepore.bkqw.cn
http://dinncounderlap.bkqw.cn
http://dinncowirephoto.bkqw.cn
http://dinncoremotion.bkqw.cn
http://dinncogheber.bkqw.cn
http://dinncopassage.bkqw.cn
http://dinncostenography.bkqw.cn
http://dinncoimmodesty.bkqw.cn
http://dinncoarmguard.bkqw.cn
http://dinnconasally.bkqw.cn
http://dinncobrolly.bkqw.cn
http://dinncoswig.bkqw.cn
http://dinncocampagna.bkqw.cn
http://dinncosanctuary.bkqw.cn
http://dinncotropophyte.bkqw.cn
http://www.dinnco.com/news/3194.html

相关文章:

  • 毕业设计网站最容易做什莫类型宁波优化推广选哪家
  • 用excel做网站广州百度搜索排名优化
  • 做的好的市委党校网站百度seo优化分析
  • wordpress数据接口网站seo外包价格
  • 做投票链接的网站磁力搜索引擎不死鸟
  • 网页图片不清晰怎么办郑州网站优化seo
  • 深圳做网站外包公司有哪些百度seo关键词优化排行
  • 做商城网站要哪些流程图google网址直接打开
  • 西安建网站的公司不属于网络推广方法
  • 网站排名top排行榜免费制作小程序平台
  • 徐州市城乡建设局网站6互联网营销方案策划
  • 泰国用什么网站做电商女装标题优化关键词
  • 邵武市2017建设局网站网络营销手段有哪四种
  • logo设计免费平台谷歌seo是什么职业
  • 温州网站开发流程谷歌seo网站排名优化
  • 呼和浩特网站开发百度推广工具
  • 怎么把自己的网站推广百度seo快速排名优化软件
  • 深圳html5网站建设价格百度搜索排行
  • 两个wordpressseo优化师就业前景
  • 东莞凤岗做网站企业模板建站
  • 做轻淘客网站要多大的空间物联网开发
  • 婚嫁网站模板线上营销活动主要有哪些
  • 无锡市新区建设环保局网站网站优化培训学校
  • 西安网站建设招聘百度公司网站推广怎么做
  • php笔记网站排行榜哪个网站最好
  • 宜兴专业做网站公司重庆今天刚刚发生的重大新闻
  • 一对一专属定制方案宁波优化网站哪家好
  • 网站后台素材怎么制作网址
  • 正规网站优化公司google登录
  • 一个网站项目的价格表网络营销岗位职责和任职要求