Skip to content

Mention defineModel() for Vue 3 #289

Description

@ShayanTheNerd

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions