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

绵阳网站的建设在线房屋设计免费图

绵阳网站的建设,在线房屋设计免费图,虚拟主机搭建wordpress,怀柔网站建设公司前言 有时候我们需要对一个组件绑定自定义 v-model#xff0c;以更方便地实现双向数据 甚至有时候#xff0c;我们想要实现绑定多个 “v-model”#xff0c;也就是多个“双向绑定”#xff0c;好在 vue 3 已经实现了可使用多个 v-model 例如#xff1a; 自定义表单输入控件…前言 有时候我们需要对一个组件绑定自定义 v-model以更方便地实现双向数据 甚至有时候我们想要实现绑定多个 “v-model”也就是多个“双向绑定”好在 vue 3 已经实现了可使用多个 v-model 例如 自定义表单输入控件 弹窗封装组件控制展示与隐藏 vue2 单个“双向绑定”的实现 其实 v-model 本质就是 value change 的语法糖监听传入内容并触发改变因此只要实现 “监听” “触发” 就可以实现自定义 v-model !-- 父组件 -- templateChild v-modelparentValue / /template script import Child from ./components/child.vue export default {name: ParentComponent,components: {Child,},data() {return {parentValue: , // 父组件数据}}, } /script style scoped langscss/style !-- 子组件 -- templateinput v-modelgetValue / /template script export default {name: ChildComponent,props: {childValue: String,},model: {prop: childValue, // 指定 v-model 要绑定的参数叫什么名字来自于 props 中定义的参数event: updateValue, // 指定要触发的事件名字将被用于 $emit},computed: {getValue: {// 这里的计算属性使用了 getter、setter可以简化代码// 可参见链接 https://cn.vuejs.org/v2/guide/computed.html#%E8%AE%A1%E7%AE%97%E5%B1%9E%E6%80%A7%E7%9A%84-setterget() {return this.childValue},set(val) {this.$emit(updateValue, val) // 触发},},}, } /script style scoped langscss/style 通过这样的方式我们就实现了自定义组件的 v-model重点在于子组件中 model 的声明和 emit 事件 vue3  vue2 中的 v-model 和 .sync 功能重叠容易混淆因此 vue3 做了统一一个组件可以多次使用 v-model 注意 vue3 移除了 model 选项就是上面示例 vue2 中的用法 model: {     prop: , // 指定 v-model 要绑定的参数叫什么名字来自于 props 中定义的参数     event: , // 指定要触发的事件名字将被用于 $emit } 单个数据双向绑定  !-- 父组件 -- templateChild v-modelparentValue / /template script setup nameParentComponent langts import Child from ./components/child.vueimport { ref } from vue;const parentValue ref() /script style scoped langscss/style !-- 子组件 -- templateinput v-modelgetValue / /template script setup nameChildComponent langts import { ref, computed, defineEmits, defineProps } from vueconst props defineProps({modelValue: {type: String,default: ,}, })const emit defineEmits([update:modelValue])const getValue computed({get() {return props.modelValue},set(newValue) {emit(update:modelValue, newValue)}, }) /script style scoped langscss/style vue3 使用特定的 modelValue 避免 value 的占用通过 update:modelValue 实现数据双向绑定 多个数据双向绑定 !-- 父组件 -- templateChild v-model:nameparentName v-model:ageparentAge / /template script setup nameParentComponent langts import Child from ./components/child.vueimport { ref } from vueconst parentName ref() const parentAge ref() /script style scoped langscss/style !-- 子组件 -- templateinput v-modelgetNameValue /input v-modelgetAgeValue / /template script setup nameChildComponent langts import { ref, computed, defineEmits, defineProps } from vueconst props defineProps({name: {type: String,default: ,},age: {type: String,default: ,}, })const emit defineEmits([update:name,update:age])const getNameValue computed({get() {return props.name},set(newValue) {emit(update:name, newValue)}, })const getAgeValue computed({get() {return props.age},set(newValue) {emit(update:age, newValue)}, }) /script style scoped langscss/style
http://www.zqtcl.cn/news/334234/

相关文章:

  • 绍兴做网站价格字体
  • asp.net网站开发实训可以不花钱做网站吗
  • 北京网站的制作设计服务器和电脑主机的区别
  • 北京网站建设的服务公司凡科网站 怎么开支付
  • 包头公司做网站知名做网站费用
  • 安徽网站建设服务平台重庆网站建公司大全
  • 有什么网站可以做中间人的相城区建设局网站
  • 房屋装修在线设计网站百度联盟广告怎么屏蔽
  • 网站,商城,app+建设域名网址注册
  • 肥西做网站设计网页页面
  • 怎样做百度推广网站iis服务器的默认网站
  • 东莞建设工程交易中心门户网站湖南设计网站机构
  • 做网站在网站建设客户
  • 河北建设厅安监站官方网站一个新手怎么做电商
  • 做结婚请柬网站有那些做网店哪个网站好
  • 做网站尽在美橙互联欧美简约风格网站设计
  • idea建设完整的网站微官网下载
  • 阿城区建设小学网站上海建设行政主管部门政务网站
  • 西丽网站建设网站怎样做才能有点击率
  • 网站建设图片大小建设部网站1667号公告
  • 做wps的网站赚钱网站建设中网站图片如何修改
  • 公司招商型网站建设怎么自己做网站挣钱
  • 红酒手机网站建设中视频自媒体注册
  • 免费网站2022年能用的网址青阳网站建设
  • 网站建设的开发方式知乎科技部网站建设合同范本
  • 兰州市建设厅官方网站做酒店的网站
  • 宠物店网站开发文档撰写洛阳市河阳建设工程有限公司网站
  • 毕业设计做网站应该学什么wordpress调用子分类
  • 怎么建网站做淘宝客用国外网站 图片做自媒体
  • 汕头建站模板搭建怎么制作有效网站