Skip to content

3 - 响应性丟失 #1632

Open
Open
@a993897020

Description

@a993897020
// 你的答案
<script setup lang="ts">
import { reactive } from "vue"

function useCount() {
  const state = reactive({
    count: 0,
  })

  function update(value: number) {
    state.count = value
  }

  return {
    state,
    update,
  }
}

// Ensure the destructured properties don't lose their reactivity
const { state, update } = useCount()

</script>

<template>
  <div>
    <p>
      <span @click="update(state.count-1)">-</span>
      {{ state.count }}
      <span @click="update(state.count+1)">+</span>
    </p>
  </div>
</template>

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @a993897020

        Issue actions

          3 - 响应性丟失 · Issue #1632 · webfansplz/vuejs-challenges