When using Vue 3's Composition API, I've noticed that inside a templte refs behave differently when they are accessed as the property of an object. I think this is best summarized by this example in the SFC Playground, but here's the key code (from a Single File Component):
<script>
import { ref } from 'vue';
export default {
setup() {
const wut = ref(false);
const obj = { wut };
return {
wut,
obj,
};
},
};
</script>
<template>
<!-- obj.wut - false -->
<h3>obj.wut - {{ obj.wut }}</h3>
<!-- !!obj.wut - true -->
<h3>!!obj.wut - {{ !!obj.wut }}</h3>
<!-- obj.wut.value - false -->
<h3>obj.wut.value - {{ obj.wut.value }}</h3>
<!-- !!obj.wut.value - false -->
<h3>!!obj.wut.value - {{ !!obj.wut.value }}</h3>
<!-- does display -->
<h3 v-if="obj.wut">display logic for this: v-if="obj.wut"</h3>
<!-- does not display -->
<h3 v-if="!obj.wut">display logic for this: v-if="!obj.wut"</h3>
<!-- typeof obj.wut - object -->
<h3>typeof obj.wut - {{ typeof obj.wut }}</h3>
</template>
Can anybody explain why it appears to treat the ref as an object in some cases and interpret its value in other cases? Is this a bug, or by design?