Skip to content

Can access t in script but not script setup? #996

Answered by kazupon
HittiGubbi asked this question in Q&A
Discussion options

You must be logged in to vote

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.

You need to use the useI18n in script setup.

<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:
https://vue-i18n.intlify.dev/guide/advanced/composition.html

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@HittiGubbi
Comment options

@CaiWenlie
Comment options

@MarcMoerkeberg
Comment options

@realtebo
Comment options

@Carlozc90
Comment options

Answer selected by HittiGubbi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants