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

3 - losing-reactivity #162

Closed
zhangmo8 opened this issue Jul 5, 2022 · 4 comments
Closed

3 - losing-reactivity #162

zhangmo8 opened this issue Jul 5, 2022 · 4 comments

Comments

@zhangmo8
Copy link

zhangmo8 commented Jul 5, 2022

// your answers
<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,
  }
}

// Make ensure the destructure without losing 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>
@plus50
Copy link

plus50 commented Jul 6, 2022

@wegi8

hi~
Could you plz explain where does this $ come from?

@zhangmo8
Copy link
Author

zhangmo8 commented Jul 6, 2022

@wegi8

hi~

Could you plz explain where does this $ come from?

@erica-plus It's just a grammar sugar on Vue.

@plus50
Copy link

plus50 commented Jul 7, 2022

@wegi8

thank you very much! 🤣
i forgot this chapter: 响应性语法糖

@bLanK-NULL
Copy link

$ grammar sugar donesn't work anymore even if I switch the version to 3.3.X

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

No branches or pull requests

3 participants