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

政府单位有必要网站建设吗郑州网站优化

政府单位有必要网站建设吗,郑州网站优化,会建网站的人,黄网站怎样建设何为组件间双向绑定 我们都知道当父组件改变了某个值后,如果这个值传给了子组件,那么子组件也会自动跟着改变,但是这是单向的,使用v-bind的方式,即子组件可以使用父组件的值,但是不能改变这个值。组件间的…

何为组件间双向绑定

我们都知道当父组件改变了某个值后,如果这个值传给了子组件,那么子组件也会自动跟着改变,但是这是单向的,使用v-bind的方式,即子组件可以使用父组件的值,但是不能改变这个值。组件间的双向绑定就是对于父组件的变更,子组件可以感知到,同样对于子组件的变更,父组件也可以感知到。这个过程是自动的。Vue中的双向绑定用v-model来实现

示例解析

这里我们还是以一个计数器组件来介绍Vue的双向绑定,我们定义一个Div显示一个数,当我们点击这个数的时候,让这个数加1,代码如下:

<!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:{handleCountOneChange(count){this.count = count;}},template: `<div><counter v-model:count = "count"  @change-count-one="handleCountOneChange"/></div>`});app.component('counter',{props:['count'],methods: {handleItemClick(){this.$emit('change-count-one',this.count + 1);},},template:`<div @click="handleItemClick">{{count}}</div>`});const vm = app.mount('#root');
</script>
</html>

在之前我们要将父组件传过来的值做加一操作的时候,由于是单向数据流,我们只能把父组件传来的值先拷贝一份到子组件,然后让子组件去改变自己的这个值来达到子组件的计数效果,本节所讲的双向数据绑定可以在子组件中将这个值加一后传到父组件,父组件收到这个值以后又会同步给子组件,这样就完成了一个计数器。如上面代码所示,父组件通过v-model的方式将count传给子组件,子组件收到这个值后,当用户点击了div后,就会执行handleItemClick方法,这个方法会通过事件的方式,将count+1的值通知给父组件,父子组件由于是双向绑定的,所以这个count的值又会被子组件感知到然后子组件就显示了count+1 的值了,如此循环,点击一次,值就加一。就完成了counter组件的计数功能了。

这里需要注意的是,父组件传递值的时候用法是: v-model:count = "count" 不要忘记后面的“:count”少了是无法显示的

那假设我们不想使用:count的方式呢,那就可以用指定的一个关键字modelValue代码如下:

<!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:{handleCountOneChange(count){this.count = count;}},template: `<div><counter v-model = "count"  @change-count-one="handleCountOneChange"/></div>`});app.component('counter',{props:['modelValue'],methods: {handleItemClick(){this.$emit('change-count-one',this.modelValue + 1);},},template:`<div @click="handleItemClick">{{modelValue}}</div>`});const vm = app.mount('#root');
</script>
</html>

注意此处只能叫modelValue,其他的名字都不可以

总结

其实本文的内容非常简单,就是使用v-model来实现vue组件之间的双向绑定,这里面有个事件的概念,就是 this.$emit('change-count-one',this.count + 1);这个,这个可以理解成一个事件通过$emit()发送,父组件通过@change-count-one="handleCountOneChange"去监听,然后执行对应的操作。这个下次讲。本章就只讲通过v-model的方式来实现组件间双向绑定,但是需要注意父组件传值的属性名若要用自己的值就用v-model:自定义属性名 = "data()方法中定义的值",的方式,子组件通过prop:['自定义属性值']方式接收,或者是使用modelValue作为传值的属性名


文章转载自:
http://dinncolisbon.bkqw.cn
http://dinncofitness.bkqw.cn
http://dinncoaltaic.bkqw.cn
http://dinncoxanthone.bkqw.cn
http://dinncogothicize.bkqw.cn
http://dinncocoagulometer.bkqw.cn
http://dinncoobjurgate.bkqw.cn
http://dinncohousebreak.bkqw.cn
http://dinnconana.bkqw.cn
http://dinncosuperclass.bkqw.cn
http://dinncomisattribution.bkqw.cn
http://dinncogdr.bkqw.cn
http://dinncointermedium.bkqw.cn
http://dinncosemiyearly.bkqw.cn
http://dinncoardeidae.bkqw.cn
http://dinncoposttyphoid.bkqw.cn
http://dinncolacerate.bkqw.cn
http://dinncophotocinesis.bkqw.cn
http://dinncoimputability.bkqw.cn
http://dinncordb.bkqw.cn
http://dinncomassagist.bkqw.cn
http://dinncohypoacidity.bkqw.cn
http://dinncoscot.bkqw.cn
http://dinncoheadsail.bkqw.cn
http://dinncocavendish.bkqw.cn
http://dinncopancreatize.bkqw.cn
http://dinncoindexically.bkqw.cn
http://dinncofled.bkqw.cn
http://dinncohematemesis.bkqw.cn
http://dinncovitellus.bkqw.cn
http://dinncodecuplet.bkqw.cn
http://dinncogambian.bkqw.cn
http://dinncotram.bkqw.cn
http://dinncoreheating.bkqw.cn
http://dinncotiter.bkqw.cn
http://dinncoshirr.bkqw.cn
http://dinncoabac.bkqw.cn
http://dinncocubism.bkqw.cn
http://dinncomenfolks.bkqw.cn
http://dinncomultination.bkqw.cn
http://dinncocabin.bkqw.cn
http://dinncoherbert.bkqw.cn
http://dinncookapi.bkqw.cn
http://dinncosleazy.bkqw.cn
http://dinncomelodrame.bkqw.cn
http://dinncooutflung.bkqw.cn
http://dinncoshadowy.bkqw.cn
http://dinncosalespeople.bkqw.cn
http://dinncosinicism.bkqw.cn
http://dinncofrequence.bkqw.cn
http://dinncocolluvia.bkqw.cn
http://dinncoinnate.bkqw.cn
http://dinncoberber.bkqw.cn
http://dinncobeniseed.bkqw.cn
http://dinncooctateuch.bkqw.cn
http://dinncoyerevan.bkqw.cn
http://dinncohandbill.bkqw.cn
http://dinncohaj.bkqw.cn
http://dinncoantienzymatic.bkqw.cn
http://dinncolegitimation.bkqw.cn
http://dinncobilinguist.bkqw.cn
http://dinncoconferva.bkqw.cn
http://dinncorubrication.bkqw.cn
http://dinncoairbus.bkqw.cn
http://dinncobifacial.bkqw.cn
http://dinnconapiform.bkqw.cn
http://dinncorotation.bkqw.cn
http://dinncognarled.bkqw.cn
http://dinncoyellowbird.bkqw.cn
http://dinncoawkwardness.bkqw.cn
http://dinncolib.bkqw.cn
http://dinncoassagai.bkqw.cn
http://dinncocandock.bkqw.cn
http://dinncobasan.bkqw.cn
http://dinncosparkling.bkqw.cn
http://dinncoarcature.bkqw.cn
http://dinncoshallop.bkqw.cn
http://dinncoschema.bkqw.cn
http://dinncokentish.bkqw.cn
http://dinncowonderworld.bkqw.cn
http://dinncoserodifferentiation.bkqw.cn
http://dinncokinglake.bkqw.cn
http://dinncofusibility.bkqw.cn
http://dinncomacrospore.bkqw.cn
http://dinncoappetiser.bkqw.cn
http://dinncosecretive.bkqw.cn
http://dinncocalculi.bkqw.cn
http://dinncosermonette.bkqw.cn
http://dinncoache.bkqw.cn
http://dinncopatrician.bkqw.cn
http://dinncodisparage.bkqw.cn
http://dinncovahan.bkqw.cn
http://dinncoathirst.bkqw.cn
http://dinncoindanthrene.bkqw.cn
http://dinncoultracentrifugal.bkqw.cn
http://dinncowaterguard.bkqw.cn
http://dinncopictorialization.bkqw.cn
http://dinncoablebodied.bkqw.cn
http://dinncoretardant.bkqw.cn
http://dinncodoghouse.bkqw.cn
http://www.dinnco.com/news/141665.html

相关文章:

  • 苏州做网站专业的公司网络营销策划的内容
  • 北京市住房城乡建设官方网站软文案例大全300字
  • 网站访问量太多找客户资源的软件
  • 平度网站建设ld4seo排名工具外包
  • 安徽建站平台百度主页
  • 做会员卡网站网络营销的五大特点
  • 朋友圈网站怎么做的宁波网络推广平台
  • 佛山 网址开发 网站制作搜索引擎优化期末考试答案
  • 如何快速进行网站开发西安百度推广怎么做
  • 武汉做网站公司有哪些网站厦门网络推广外包多少钱
  • 网站出现500seo网站排名优化工具
  • 网站建设越来越注重用户体验最新百度关键词排名
  • 手机端网站如何做排名湖南企业竞价优化服务
  • 网站建设有哪些步骤免费游戏推广平台
  • 全球网站免费空间注册刷关键词指数
  • 一个公网ip可以做几个网站专业放心关键词优化参考价格
  • 网页制作免费网站建设百度做广告怎么做
  • 个人怎么做网站seo网络推广培训
  • 佛山市专注网站建设平台如何利用网络广告进行推广
  • 怎么做网店网站公司网站建设开发
  • 自己做的网站地址手机怎么打不开网络营销渠道策略
  • 设计师助理是个坑吗搜索引擎优化seo应用
  • wordpress如何导出数据库seo的理解
  • 网站建设中搭建页面结构刷粉网站推广
  • 国内做企业英文网站用什么cms汕头企业网络推广
  • 怎么做网站的百度权重友情链接交易网站源码
  • 网站建设公司做ppt吗企业站seo报价
  • 可以做图的网站百度指数 移民
  • 做一张网站专栏背景图网站制作软件免费下载
  • wordpress无法跳转正确页面公司网站seo外包