这是用户在 2024-3-22 15:10 为 https://github.com/vuejs/rfcs/discussions/503 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Skip to content
You have no unread notifications
vuejs  /   rfcs  /   Discussions #503  /  

[Core Team RFC] New SFC macro: defineModel #503
[核心团队 RFC] 新 SFC 宏:defineModel #503

yyx990803 started this conversation in RFC Discussions
Apr 28, 2023 · 42 comments · 95 replies

Replies: 42 comments 95 replies

3 replies
@yyx990803

yyx990803 Apr 28, 2023
Maintainer Author

But not this?: 但不是这个?

<script setup>
const modelValue = defineModel()
</script>
<template>
  <input v-model="modelValue" />
</template>

"opposite of obvious", "unintuitive", "the bad parts", "would get abused". Yeah it's very clear you don't actually understand it whatsoever. What is there not to get? It's so easy. It's a two way binding of a value. The model is a reference to the one in the v-model, as if they're the same value. Oh no, props and emits are registered without you knowing, well so do defineProps and defineEmits, better stop using those too.
"与显而易见相反"、"不直观"、"不好的部分"、"会被滥用"。是啊,很明显你根本就不懂。有什么不明白的?这很简单。这是值的双向绑定。模型是对 v 模型中模型的引用,就好像它们是同一个值。哦,不对,道具和 Emits 是在你不知道的情况下注册的,defineProps 和 defineEmits 也是,最好也别再用了。

This function has pretty much the same usage as defineModel, you just need to declare props and emits and pass them through:
该函数的用法与 defineModel 基本相同,您只需声明道具和发射并将它们传递过去即可:

const props = defineProps(['modelValue'])
const emits = defineEmits(['update:modelValue'])
const modelValue = defineModel(props, emits)

function defineModel(props, emit, name = 'modelValue'){
  return computed({
    get: () => props[name],
    set: value => emits(`update:${name}`, value)
  })
}

Wow, Composition API so complicated and magic. Only reason it looks dumb is out of my control and now they're fixing it with defineModel. You probably write all those god awful comments saying composition api sucks because you don't understand .value and this. is way easier (despite the fact you can just have a reactive variable and call it that). You probably think mixins are good too (I never want to find out if this is a good insult or not, but I trust Vue in this when they said it was terrible). You could even put this thing in a composable (which are actually good mixins) and have Nuxt auto import it for you. So opaque and unextendable
哇,Composition API 如此复杂而神奇。它看起来很蠢的唯一原因是我无法控制,现在他们用 defineModel 修正了它。你可能写了那么多糟糕透顶的评论,说组成应用程序接口很烂,因为你不理解 .valuethis. 更简单(尽管事实上你可以使用一个反应式变量并调用它 that )。你可能也认为 mixins 很好(我从来没想过这是否是一种侮辱,但我相信 Vue,因为他们说这很糟糕)。你甚至可以把这个东西放在可组合中(其实这也是很好的混合类),然后让 Nuxt 自动为你导入。不透明且不可扩展

Wanna know why you don't think it's obvious? Because defineModel is extremely obvious and intuitive and the previous way was extremely unobvious and intuitive, so when you explain how you would do the same previously, as I just did, it looks really stupid. Which is kinda why the new way exists.
想知道你为什么不认为这是显而易见的吗?因为 defineModel 是非常明显和直观的,而之前的方法是非常不明显和不直观的,所以当你解释之前如何做同样的事情时,就像我刚刚做的那样,看起来非常愚蠢。这也是新方法存在的原因。

New people will find this really easy, because it is, and you can find it easy too if you stop comparing it to the dumbass way of doing it which just makes it seem complicated.
新手会觉得这很容易,因为它确实很容易,如果你不再把它与那些只会让人觉得复杂的笨方法相比较,你也会觉得很容易。

Kinda reminds me of the time where someone said 24 hour time was more complicated than 12 hour time. This has to be satire.
这让我想起有人说 24 小时制比 12 小时制更复杂。这一定是在讽刺。

TLDR: It's just a two way binding/reference to a value. It's really, really easy. Composition API based. (and people who use Options API but know it's not as good).
简要说明:这只是对一个值的双向绑定/引用。非常非常简单。基于 Composition API。(以及使用 Options API 但知道它没有那么好的用户)。

@angelhdzmultimedia

3 replies
@ThomasBerne

@alann-sapone

@IARI

7 replies
@alann-sapone

@coolCucumber-cat

@joezimjs

@alann-sapone

@coolCucumber-cat

2 replies
@ThomasBerneHCSE

@kstan79

4 replies
@yyx990803

yyx990803 Dec 12, 2023
Maintainer Author

@yyx990803

yyx990803 Dec 28, 2023
Maintainer Author

@erropix

@jods4

1 reply
@coolCucumber-cat

1 reply
@skirtles-code

0 replies

1 reply
@yyx990803

yyx990803 Dec 12, 2023
Maintainer Author

0 replies

1 reply
@yyx990803

yyx990803 Dec 28, 2023
Maintainer Author

1 reply
@erropix

0 replies

0 replies

7 replies
@skirtles-code

@yyx990803

yyx990803 Jan 11, 2024
Maintainer Author

@nined9

@jods4

@HeuHax

1 reply
@Shinigami92

Add a comment

Select a reply

Slash commands
Beta
Give feedback
Slash commands
Beta
Give feedback

An unexpected error has occurred

Remember, contributions to this repository should follow our GitHub Community Guidelines.
Labels
None yet
  • Create issue from discussion

    Create issue from discussion

    The original post will be copied into a new issue, and the discussion will remain active.