码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Vue3中使用v-model高级用法参数绑定传值


    Vue3中使用v-model高级用法参数绑定传值

      • 单个输入框传值
      • 多个输入框传值,一个组件接受多个v-model值

    单个输入框传值

    App.vue

    <template>
      <p>{{firstName}}</p>
      <hello-world v-model="firstName"></hello-world>
    </template>
    
    <script setup>
    import {ref} from "vue";
    import HelloWorld from "./components/HelloWorld.vue";
    
    const firstName = ref('firstName');
    
    </script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    HelloWorld.vue

    <template>
      <input type="text"
             :value="modelValue"
             @input="$emit('update:modelValue',$event.target.value)">
    </template>
    
    <script setup>
    defineProps(["modelValue"]);
    defineEmits(["update:modelValue"]);
    </script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    多个输入框传值,一个组件接受多个v-model值

    App.vue

    <template>
      <p>{{firstName}}</p>
      <p>{{lastName}}</p>
      <hello-world v-model:firstName="firstName" v-model:lastName="lastName"></hello-world>
    </template>
    
    <script setup>
    import {ref} from "vue";
    import HelloWorld from "./components/HelloWorld.vue";
    
    const firstName = ref('firstName');
    const lastName = ref("lastName");
    
    </script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    HelloWorld.vue

    <template>
      <input type="text"
             :value="firstName"
             @input="$emit('update:firstName',$event.target.value)"/><br/>
      <input type="text"
             :value="lastName"
             @input="$emit('update:lastName',$event.target.value)"/>
    </template>
    
    <script setup>
    defineProps(["firstName","lastName"]);
    defineEmits(["update:firstName","update:lastName"]);
    </script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
  • 相关阅读:
    《优化接口设计的思路》系列:第一篇—接口参数的一些弯弯绕绕
    sql开发学习(1)之group by,left join
    振弦式测缝(位移)计表面裂缝监测
    厚壁菌门/拟杆菌门——肠道菌群的阴阳面,代表什么
    JavaScript判断是否为空对象的几种方法
    【饭谈】测试行业找工作最看重什么?
    RAG、数据隐私、攻击方法和安全提示
    我的第一个NPM包:panghu-planebattle-esm(胖虎飞机大战)使用说明
    第10章 初识SqlSugarCore之NPOI Excel导出
    syntax error near unexpected token `(‘
  • 原文地址:https://blog.csdn.net/weixin_42202992/article/details/133799159
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号