defineModel ref not reactive #10600
Answered
by
LinusBorg
ant32t
asked this question in
Help/Questions
-
Is this expected that App.vue <script setup>
import {reactive} from 'vue'
import Comp from './Comp.vue'
</script>
<template>
<Comp :model-value="[]"/>
</template> Comp.vue <script setup>
import { watchEffect, ref } from 'vue';
const model = defineModel();
const msg = ref(0);
watchEffect(() => msg.value = model.value.length);
model.value.push(5);
</script>
<template>
lenght of model: {{ msg }}
</template> |
Beta Was this translation helpful? Give feedback.
Answered by
LinusBorg
Mar 26, 2024
Replies: 1 comment
-
The ref is reactive, but not deep-reactive. And the prop value you provided is a plain, nonreactive array. It works like a normal prop in that regard - if you pass something non-reactive down through a prop, changes will not trigger anything. Changing the array will not trigger anything, as you did not rlassign a new value to the model ref |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ant32t
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ref is reactive, but not deep-reactive. And the prop value you provided is a plain, nonreactive array.
It works like a normal prop in that regard - if you pass something non-reactive down through a prop, changes will not trigger anything.
Changing the array will not trigger anything, as you did not rlassign a new value to the model ref