Skip to content

6 - 浅层 ref #2142

@jay6697117

Description

@jay6697117
<script setup lang="ts">
import { ref, reactive, shallowRef, watch } from 'vue';

const state = shallowRef({ count: 1 });
// const state = ref({ count: 1 })
// const state = reactive({ count: 1 })

// Does NOT trigger
watch(
  state,
  () => {
    console.log('State.count Updated', state.value.count);
    // console.log("State.count Updated", state.count)
  },
  { deep: true }
);

/**
 * Modify the code so that we can make the watch callback trigger.
 */
// state.value.count = 2
// state.count = 200
state.value = { count: 200 };
</script>

<template>
  <div>
    <p>
      {{ state.count }}
    </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

        @jay6697117

        Issue actions

          6 - 浅层 ref · Issue #2142 · webfansplz/vuejs-challenges