Vue3 Defineprops Withdefault

Posted on  by admin
Modified1 month ago.

I've trying to set the default value of a prop to a locale value using i18n.

Wenfang Du
5,399

I've tried the following but this gives me an error:. defineProps are referencing locally declared variables. What's the best way to handle this? 2525 bronze badges. 1,50311 gold badge1515 silver badges3535 bronze badges. 1515 silver badges3535 bronze badges.

defineProps is a compiler macro, so you can't use any runtime values within it. I'd suggest to use a local variable for this default:. Also described here in the last bullet point: https://v3.vuejs.org/api/sfc-script-setup.html#defineprops-and-defineemits.

Not the answer you're looking for? Browse other questions tagged internationalizationvuejs3 or ask your own question.

22 gold badges2222 silver badges5252 bronze badges.

RichardRichard
9341

JavaScript 52篇. Vue 3 introduced us to the Composition API - a different way of handling reactive data using ref and reactive in Vue.js.

CircleImage.view

MyView.view

It received a lot of positive feedback but also some concerns about the verbosity of the Composition API usage inside SFCs.

oHooHo
45.7k