-
Notifications
You must be signed in to change notification settings - Fork 342
Closed
Labels
misalignmentMisalign with the latest RFCMisalign with the latest RFC
Description
The reactive
can't observe a Array
, my code like this:
<template>
<div>
<button @click="handleAdd">Add count</button>
</div>
</template>
<script>
import Vue from "vue";
import { setup, reactive, ref, watch } from "@vue/composition-api";
const observableArray = Vue.observable([{ value: 1 }]);
export default {
setup() {
const reactiveArray = reactive([{ value: 1 }]);
const reactiveObject = reactive({ value: 1 });
const refArray = ref([{ value: 1 }]);
const reactiveDeepArray = reactive({parent: [{ value: 1 }]})
watch(
() => reactiveArray[0].value,
val => {
// I think this should be execute when I click the button every time,
// but it doesn't
console.log("reactiveArray changed", val);
}
);
watch(
() => reactiveObject.value,
val => {
// This will execute when I click the button every time
console.log("reactiveObject changed", val);
}
);
watch(
() => refArray.value[0].value,
val => {
// This will execute when I click the button every time
console.log("refArray changed", val);
}
);
watch(
() => observableArray[0].value,
val => {
// This will execute when I click the button every time
console.log("observableArray changed", val);
}
);
watch(
() => reactiveDeepArray.parent[0].value,
val => {
// This will execute when I click the button every time
console.log("reactiveDeepArray changed", val);
}
);
function handleAdd() {
reactiveArray[0].value++
reactiveObject.value++
refArray.value[0].value++
observableArray[0].value++
reactiveDeepArray.parent[0].value++
}
return {
handleAdd
};
}
};
</script>
So, when I pass a Array
to reactive
, it won't be observed. But if the Array is wrapped by a object
, it can be observed. I think it's a bug. If it's a feature, why?
akihiro07, Nunatic02, don-boldyrev and turbobuilt
Metadata
Metadata
Assignees
Labels
misalignmentMisalign with the latest RFCMisalign with the latest RFC