ByteNote LogoByteNote

Navigation

  • Blog
  • 工具

    © 2025 ByteNote. All rights reserved.

    在Vue3 setup 中使用 v-model

    Mar 27, 20223 min read

    How to use v-model on component in vue 3 script setup

    <template>
      <div>
        <input v-model="model">
      </div>
    </template>
    
    <script setup>
    import { computed } from 'vue'
    
    const props = defineProps({
      modelValue: {
        type: [String, Number],
        default: ''
      }
    })
    
    const emit = defineEmits(['update:modelValue'])
    
    const model = computed({
      get () {
        return props.modelValue
      },
    
      set (value) {
        return emit('update:modelValue', value)
      }
    })
    </script>
    

    相关文章

    gitea docker 搭建配置文件

    该配置描述了一个使用Gitea 1.16.4镜像的Docker服务,它通过MySQL数据库运行,配置了特定的环境变量和网络设置,同时依赖于另一个MySQL服务。

    SwiftUI CaseIterable 的代码演示

    SwiftUI中演示了如何使用CaseIterable枚举`Fruit`及其四个值(苹果、香蕉、橙子、葡萄)在视图中循环显示。

    JS 下载文件的封装

    该代码提供了两个JavaScript函数`downloadByData`和`downloadByUrl`,用于通过数据或URL下载文件,并支持自定义文件名和MIME类型。

    Flutte 的问号和感叹号

    Flutter 中使用问号和感叹号进行空值检查和强制非空断言,确保代码在处理可能为空的变量时更加安全和高效。

    JS 类型判断封装

    该代码封装了一系列JavaScript类型判断函数,包括函数、对象、日期、数值、异步函数、Promise、字符串、布尔和数组等。