toValue() Normalise Values, Refs and Getters

Last updated: 2026-10-22

toValue() Normalise Values, Refs and Getters

toValue() resolves a plain value, ref or getter into the current value — reusable functions can accept any of the three.

GroupReactivity: Utilities
KindAPI
ScopeComponent
Vue Version3.3+
SSR SupportYes

📝 Syntax

toValue(1)              // 1
toValue(count)          // count.value
toValue(() => count.value)  // count.value (evaluated each call)

⚙️ Arguments

sourceA plain value, ref or getter function

Returns:The resolved current value

▶ Example

Edit the code below and see the live result:

Output:

Shows '42'.

💡 Key Points

💡 Tip Use it in composable signatures so callers may pass values, refs or getters.
ℹ️ Note The getter form expresses a dependency that computed can track.
⚠️ Warning Available in 3.3+ only; older projects need manual isRef handling.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Difference from unref?
A toValue also evaluates getters on each call; unref only unwraps refs.
Q Why not require refs?
A It keeps composables flexible for static values, reactive state or computed logic.
Q Is it auto-unwrapped in templates?
A It is a runtime helper called in script logic, not template state.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏