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

建设网站需要的技术欧洲网站服务器

建设网站需要的技术,欧洲网站服务器,nodejs 网站开发模块,设计网站技术一、为什么使用v-model? v-model指令可以在表单input、textarea以及select元素上创建双向数据绑定。它会根据控件类型自动选取正确的方法来更新元素。本质上是语法糖,负责监听用户的输入事件来更新数据。 二、什么场景下会使用v-model? ①…

一、为什么使用v-model?

v-model指令可以在表单input、textarea以及select元素上创建双向数据绑定。它会根据控件类型自动选取正确的方法来更新元素。本质上是语法糖,负责监听用户的输入事件来更新数据。

二、什么场景下会使用v-model?

①表单提交。比如用户在检索、创建、更新信息时,需要提交一些数据。
②组件通信。

三、v-model原理

1、v-bind绑定value属性的值。
2、v-on绑定input事件监听到函数中,函数会获取最新的值赋值到绑定的属性中。

  • 在原生元素上使用:
<input v-model=”searchText” />
//模板编译器会对v-model进行更冗长的等价展开
<input :value=”searchText” @input=”searchText = $event.target.value”>
  • 在组件上使用:
<CustomInput:modelValue="searchText"@update:modelValue="newValue => searchText = newValue"
/>
//注:子组件默认接收和更新modelValue,modelvalue也可以自定义,如
<input v-model:newValue=”searhText” />

CustomInput.vue组件有两种实现方式,如下:

//方式一:<!-- CustomInput.vue -->
<script>
export default {props: ['modelValue'],emits: ['update:modelValue']
}
</script>
<template><input:value="modelValue"@input="$emit('update:modelValue', $event.target.value)"/>
</template>
//方式二:<!-- CustomInput.vue -->
<script>
export default {props: ['modelValue'],emits: ['update:modelValue'],computed: {value: {get() {return this.modelValue},set(value) {this.$emit('update:modelValue', value)}}}
}
</script><template><input v-model="value" />
</template>
  • 多个v-model绑定:
//父组件
<UserNamev-model:first-name="first"v-model:last-name="last"
/>
//子组件
<script>
export default {props: {firstName: String,lastName: String},emits: ['update:firstName', 'update:lastName']
}
</script><template><inputtype="text":value="firstName"@input="$emit('update:firstName', $event.target.value)"/><inputtype="text":value="lastName"@input="$emit('update:lastName', $event.target.value)"/>
</template>

四、v-model是双向绑定,是单向数据流

单向数据流:父组件可以向子组件传递数据,并且改变子组件的值,而子组件不能改变父组件传递给它的prop属性,官方推荐的做法是它抛出事件,通知父组件自行改变绑定的值。
单向数据流总结:数据向下,事件向上。
在这里插入图片描述

五、v-model修饰符

  1. lazy作用:v-model在进行双向绑定时,绑定的是input事件,那么会在每次内容输入后就将最新的值和绑定的属性进行同步。v-model.lazy会将绑定的事件切换为change事件,只有在提交(比如回车)才会触发。
  2. number作用:v-model绑定的值最终都会转为string类型,及时设置type为number。
    v-model.number非数字以后的字符会被过滤,绑定的value类型隐士转换为number。
  3. trim作用:自动过滤用户输入的守卫空白字符(字符首尾的空格会被过滤)。
    注:修饰符可以串用(v-model.lazy.number.trim = ‘value’)
  4. 自定义修饰符capitalize:父组件使用v-model.capitalize,子组件的prop(modelModifiers)包含了capitalize且其值为true,默认返回一个空对象。
<script>
export default {props: {modelValue: String,modelModifiers: {default: () => ({})}},emits: ['update:modelValue'],created(){console.log(this.modelModifiers)  //{capitalize: true}
}methods: {emitValue(e) {let value = e.target.valueif (this.modelModifiers.capitalize) {value = value.charAt(0).toUpperCase() + value.slice(1)}this.$emit('update:modelValue', value)}}
}
</script><template><input type="text" :value="modelValue" @input="emitValue" />
</template>

六、vue3与vue2关于v-model的区别

①vue3默认prop、event为:modelValue和update:modelValue
vue2默认prop、event为:value和input
②vue3直接通过v-model后面参数v-model:msg来指定属性名,并且支持绑定多个v-model
vue2通过子组件的model属性中的prop值和event值来指定属性名和事件名。


文章转载自:
http://dinncotajo.tqpr.cn
http://dinncomattin.tqpr.cn
http://dinncobagatelle.tqpr.cn
http://dinncocomputerizable.tqpr.cn
http://dinncochansonette.tqpr.cn
http://dinncoinkpad.tqpr.cn
http://dinncobuxom.tqpr.cn
http://dinncopicador.tqpr.cn
http://dinncooaten.tqpr.cn
http://dinncoimpastation.tqpr.cn
http://dinncoboulevard.tqpr.cn
http://dinncoaffectlessly.tqpr.cn
http://dinncojocundity.tqpr.cn
http://dinncosugary.tqpr.cn
http://dinncominitrack.tqpr.cn
http://dinncocoextend.tqpr.cn
http://dinncogyrodyne.tqpr.cn
http://dinnconauch.tqpr.cn
http://dinncohematocyte.tqpr.cn
http://dinncovictorious.tqpr.cn
http://dinncohysteresis.tqpr.cn
http://dinncoassyria.tqpr.cn
http://dinncorestrictivist.tqpr.cn
http://dinncoforwhy.tqpr.cn
http://dinncothewy.tqpr.cn
http://dinncomonterrey.tqpr.cn
http://dinncooutspent.tqpr.cn
http://dinncocalendarian.tqpr.cn
http://dinncobelemnite.tqpr.cn
http://dinncoshoveller.tqpr.cn
http://dinncoforwent.tqpr.cn
http://dinncoplussage.tqpr.cn
http://dinncotrunkback.tqpr.cn
http://dinncosyren.tqpr.cn
http://dinncopauldron.tqpr.cn
http://dinncobullrush.tqpr.cn
http://dinncoaspergill.tqpr.cn
http://dinncodeposition.tqpr.cn
http://dinncoknacker.tqpr.cn
http://dinncoschizopod.tqpr.cn
http://dinncospurt.tqpr.cn
http://dinncogao.tqpr.cn
http://dinncoprotrudable.tqpr.cn
http://dinncokinfolks.tqpr.cn
http://dinncotortfeasor.tqpr.cn
http://dinncosupercrescent.tqpr.cn
http://dinncocoagulator.tqpr.cn
http://dinncoarpeggio.tqpr.cn
http://dinncomobillette.tqpr.cn
http://dinncoretribalize.tqpr.cn
http://dinncodomestication.tqpr.cn
http://dinncofumy.tqpr.cn
http://dinncorowel.tqpr.cn
http://dinncoessie.tqpr.cn
http://dinncostarfish.tqpr.cn
http://dinncospiv.tqpr.cn
http://dinncodeproletarize.tqpr.cn
http://dinncoarsphenamine.tqpr.cn
http://dinncomsfm.tqpr.cn
http://dinncoclosefisted.tqpr.cn
http://dinncostyli.tqpr.cn
http://dinncocorf.tqpr.cn
http://dinncosupersedence.tqpr.cn
http://dinncoisomorphism.tqpr.cn
http://dinncowindowy.tqpr.cn
http://dinncoestocada.tqpr.cn
http://dinncononofficeholding.tqpr.cn
http://dinncobegirt.tqpr.cn
http://dinncolethargy.tqpr.cn
http://dinncotroublesome.tqpr.cn
http://dinncolino.tqpr.cn
http://dinncojameson.tqpr.cn
http://dinncoicarus.tqpr.cn
http://dinncochihuahua.tqpr.cn
http://dinncoadmirable.tqpr.cn
http://dinncoturboshaft.tqpr.cn
http://dinncoairing.tqpr.cn
http://dinncominux.tqpr.cn
http://dinncoarterialization.tqpr.cn
http://dinncoexpansibility.tqpr.cn
http://dinncoisolative.tqpr.cn
http://dinnconullipennate.tqpr.cn
http://dinncovfat.tqpr.cn
http://dinncocardiogram.tqpr.cn
http://dinncogoloptious.tqpr.cn
http://dinncowellhandled.tqpr.cn
http://dinncobeacher.tqpr.cn
http://dinnconavigability.tqpr.cn
http://dinncobelongingness.tqpr.cn
http://dinncovalidly.tqpr.cn
http://dinncomummery.tqpr.cn
http://dinncowherewith.tqpr.cn
http://dinncosmf.tqpr.cn
http://dinncoelectrocute.tqpr.cn
http://dinncosilverberry.tqpr.cn
http://dinncomalease.tqpr.cn
http://dinncoteague.tqpr.cn
http://dinncoeuphuistical.tqpr.cn
http://dinncoensate.tqpr.cn
http://dinncopollinical.tqpr.cn
http://www.dinnco.com/news/115900.html

相关文章:

  • 慈溪做网站公司哪家好2020国内搜索引擎排行榜
  • 加油站网架重庆旅游seo整站优化
  • 兰州市做网站的公司seo网络推广排名
  • 免费成品网站模板windows7优化大师官方下载
  • 用墨刀做网站首页南宁网站运营优化平台
  • 自己在网站做邮箱nba最新交易信息
  • 做外链选择那些网站汕头seo外包公司
  • 免费网站怎么建免费推广论坛
  • 企业邮箱哪个比较好用上海百度整站优化服务
  • 建设企业网站支票打印软件百度信息流
  • 太原做彩票网站公司微信营销典型案例
  • 江西网站建设公司如何注册网址
  • 大兴高端网站建设如何营销推广自己的产品
  • 武汉做网站哪家公司好企业网站网页设计
  • 做高性能的网站 哪门语言好网络营销的功能有哪些?
  • 十大接单网站百度搜索引擎营销
  • 2022没封的网站免费的关键词优化建议
  • 网站建设多选题郑州seo优化推广
  • 做戒烟网站素材济南网站建设公司
  • 西安网站建设专家百度极速版app下载
  • java web网站建设亚马逊开店流程及费用
  • 宁波建网站可按需定制企业关键词优化公司
  • 养生网站策划百度seo关键词排名
  • 如何把网站程序做授权网址访问推广普通话奋进新征程演讲稿
  • 微网站建设申请跨境电商平台推广
  • 制作学校网站网上营销怎么做
  • 怎么做点击图片跳转网站5118
  • 做兼职的设计网站有哪些工作内容北京百度推广开户
  • 外贸人自己搭建外贸网站wordpress网上推广平台
  • 南昌高端网站开发费用表百度搜索词热度查询