Skip to content

3 - losing-reactivity #1919

Open
Open
@oreo2990

Description

@oreo2990
<script setup lang="ts">
import { reactive ,toRefs} from "vue"

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

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

  return {
    state:toRefs(state),
    update,
  }
}

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


</script>

<template>
  <div>
    <p>
      <span @click="update(count-1)">-</span>
      {{ count }}
      <span @click="update(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

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @oreo2990

        Issue actions

          3 - losing-reactivity · Issue #1919 · webfansplz/vuejs-challenges