I'm trying to create a component that can be used via destructuring and as js object.
Destructuring works fine, but with js object, I'm forced to write obj.field.value instead of just obj.field. Is it expected behavior?
I'm using composition-api plugin.
Playground: https://jsfiddle.net/3mzve8oy/21/
<div id="app">
<h2 @click="ctx.fn">{{ ctx.counter }} {{counter}} </h2>
</div>
const { reactive, toRefs } = VueCompositionAPI;
const useCounter = () => {
const ctx = reactive({
counter: 2,
// ...
});
const fn = () => {
console.log('Called', ctx.counter);
}
setInterval(() => ctx.counter += 1, 1000);
return {...toRefs(ctx), fn};
}
new Vue({
el: "#app",
setup() {
const ctx = useCounter();
const { counter } = useCounter();
return { ctx, counter };
}
})
Expected output: 0 0
Actual output: { "value": 0 } 0