I'm using Vue's Composition API. When I write some code that adds a property to a ref object, the template renderer does not seem to detect the change. Here is my code:
<template>
<div id="app">
<button @click="updateObj">Click</button>
<div v-if="obj[1]">{{ obj[1] }}</div>
</div>
</template>
<script>
import { defineComponent, ref } from "@vue/composition-api";
export default defineComponent({
name: "App",
setup() {
const obj = ref({});
const updateObj = () => {
obj.value[1] = "hello";
console.log(obj.value);
};
return {
obj,
updateObj,
};
},
});
</script>
Clicking on the button calls updateObj which then sets the property "1" on obj to "hello". If obj[1] is set, you should see "hello" in the browser, but nothing is displayed. Here's a codepen to the demo.
I've been using the Composition API for months now and feel like I've gotten the hang of it, but I have no idea what's going on here. I've also tried reactive instead of ref but still no luck.