Search code examples
vue.jsnuxt.jsnuxt-i18n

I want to use t method for href of a tag and custom data attribute instead of nuxt-link when using Nuxt.js + i18n


Dynamic multilingual sites from the backend to the replacement of large sites I changed the language, but this time I am trying for the first time to do it at the front desk (Nuxt.js + i18n).

<a href="https://gooogle/en.com" data-link="fugafuga">

Without using nuxt-link

<template>
  <a href="https://gooogle/{{t('locale')}}.com" data-link="{{t('hogehoge')}}" >
</template>

Is it possible to divert and use a tag as it is? (In the above writing method, an error occurred and it was useless, so please teach me a workaround) I18n t method wrapped in quotes in inside tag quote How do I write it?

Such a shape is desirable because the scale is too large We apologize for the inconvenience, but we would appreciate it if you could teach us.

thank you.


Solution

  • Suggested fix:

    <template>
      <a :href="`https://google/${t('locale')}.com`" :data-link="t('hogehoge')"></a>
    </template>
    

    You can read more about data binding with Vue/Nuxt here: https://v2.vuejs.org/v2/guide/class-and-style.html#Object-Syntax