TLDR: I expect .value to work in the template section but it doesn't.
Everywhere I look, even in the official Vue 3 docs, I am told that (paraphrasing) "I don't have to use '.value'" when using refs in the template section because, I quote, "For convenience, refs are automatically unwrapped when used inside templates (with a few caveats).".
Nowhere did I find that I am explicitly required not to use the ".value" property when in the template section. However when I try to use {{ myConstant.value }} in the template section it doesn't work and I get errors.
So is there a way how to use ".value" in the template section when using ref() or is the documentation's (and other unofficial tutorials') wording simply misleading? Perhaps a config in Vue somewhere that I can alter or an alternative non-mustache syntax or something?
The reason I ask is that I actually want to use ".value" in the template section. Why? Because of consistency. I want to see the same consistent syntax everywhere, wherever possible. The less syntax exceptions the better in my book. I don't consider the automatic unwrapping to be a convenience feature - I consider it to be the opposite.
Thank you!
No, you can't. The property's value is directly accessed in the
<template>when using SFC.Calling this component would result in a
Uncaught (in promise) TypeError: $setup.restaurant.value is undefinedThe
.valueonly works in the composition API syntax because of how it's actually ran behind the scenes, I think composition API translates to options API which later gets translated into vanilla javascript, and in composition API you access ref values using the keywordthis..