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

Mention defineModel() for Vue 3 #289

Open
ShayanTheNerd opened this issue Jan 13, 2025 · 0 comments
Open

Mention defineModel() for Vue 3 #289

ShayanTheNerd opened this issue Jan 13, 2025 · 0 comments

Comments

@ShayanTheNerd
Copy link

In "emit to parent" feature for Vue 3, the code can be simplified to the following:

App.vue

<script setup>
import { ref } from "vue";

import AnswerButton from "./AnswerButton.vue";

const isHappy = ref(true);
</script>

<template>
  <p>Are you happy?</p>

  <AnswerButton v-model="isHappy" />
  
  <p style="font-size: 50px">
    {{ isHappy ? "😀" : "😥" }}
  </p>
</template>

AnswerButton.vue

<script setup>
const isHappyModel = defineModel({ type: Boolean });
</script>

<template>
  <button @click="isHappyModel = true">YES</button>
  <button @click="isHappyModel = false">NO</button>
</template>

I understand that the point is to demonstrate Vue's syntax and feature in this specific scenario, but you should either change the example to a more practical one in which defineModel() isn't enough, or mention this feature below the current example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant