ByteNote LogoByteNote

Navigation

  • Blog
  • 工具

    © 2025 ByteNote. All rights reserved.

    vue 3 computed getter setter

    Jul 1, 20224 min read
    const count = ref(1)
    const plusOne = computed({
      get: () => count.value + 1,
      set: val => {
        count.value = val - 1
      }
    })
    
    plusOne.value = 1
    console.log(count.value) // 0
    
    <script setup>
    import { computed } from 'vue'
    import { useStore } from 'vuex'
    const store = useStore()
    
    const email = computed({
        get() {
          return store.state.email
        },
        set(value) {
          store.commit("setEmail", value)
        }
    })
    </script>
    
    <template>
        <input type="email" v-model="email" />
    </template>
    

    相关文章

    解决 Cannot run with sound null safety, because the following dependencies

    在Android Studio配置中,通过在启动项添加"--no-sound-null-safety"来临时解决因依赖问题导致的无法运行问题。

    next.js 使用pm2

    使用pm2以"office-web"为名启动next.js应用。

    Golang中如何扩展结构体字段?

    在 Golang 中,通过类型嵌入可以扩展结构体字段,但需注意处理同名字段以避免冲突。

    iOS APP技术支持网站

    iOS APP技术支持网站提供24小时邮件服务,邮箱地址为[email protected],以解决用户使用产品时遇到的问题。

    MAC pbcopy 命令行的使用

    `pbcopy` 是 macOS 中的命令行工具,用于将文本复制到剪贴板,支持复制命令行输出、文件内容、指定文本,并可清空剪贴板。