Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 defineModels 的时候应当和直接声明保持一致,是否能详细说明一下 passive 的意义 #565

Open
5 tasks done
zhengyimeng opened this issue Nov 24, 2023 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@zhengyimeng
Copy link

Describe the bug

# App.vue
<script setup lang="ts">
import { ref, watch } from "vue";
import HelloWorld from "./components/HelloWorld.vue";

const msg = ref({ name: 123, label: 789 });
const msg2 = ref({ name: 65, label: 456 });

watch([msg, msg2], () => {
  console.log(1);
});

[msg.value, msg2.value] = [msg2.value, msg.value];
</script>

<template>
  <HelloWorld v-model:msg="msg" v-model:msg2="msg2" />
</template>

// HelloWorld.vue

<script setup lang="ts">
let { msg, msg2 } = defineModels<{
  msg: number;
  msg2: number;
}>();

const onClick = () => {
  [msg2.value, msg.value] = [msg.value, msg2.value];
};
</script>

<template>
  <button @click="onClick()">adsfsdf</button>
</template>

第一次的交换,watch 只会监听到一次
当执行 HellowWorld 里的onClick 时,watch 会监听到两次

// 文档
image
我试了一下,如果编译后是这样的话,watch 监听到也是一次
所以到底是哪里出错了

Reproduction

https://github.com/zhengyimeng/test-defineModels.git

System Info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1
    Memory: 180.11 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: 4.0.0 - ~/.nvm/versions/node/v18.16.1/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
    pnpm: 8.10.2 - ~/.nvm/versions/node/v18.16.1/bin/pnpm
    bun: 0.1.8 - ~/.bun/bin/bun
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 16.2

Used Package Manager

yarn

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@sxzz sxzz added the help wanted Extra attention is needed label Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants