Can access t in script but not script setup? #996
-
I have a basic Vue single file component with the following kind of a script element:
This works without problems: the value of The problem is that I would prefer to use script setup instead, as that is what I am using everywhere else, but I have been unable to find information how to achieve that. E.g. the following two attempts result in error about t being undefined:
So how can I access t inside a script setup element? I naturally want to do this in same manner as in the normal script, that is, without explicit import of t in different single file components. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You need to use the <script setup>
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const someProperty = computed(() => t.("some.property"));
</script> See the details composition API section: |
Beta Was this translation helpful? Give feedback.
You need to use the
useI18n
in script setup.See the details composition API section:
https://vue-i18n.intlify.dev/guide/advanced/composition.html