0

I have a line of jQuery code:

$("#showNames").text("{{ $t('hide_labels') }}");

I'd like to set text of the #showNames element with the value taken from my vue-i18n instance, dependent on user localization. When it's written this way, I get the literal moustache syntax contents. Is there any way to get the values displayed?

Bert
  • 80,741
  • 17
  • 199
  • 164
AbreQueVoy
  • 1,748
  • 8
  • 31
  • 52

2 Answers2

1

You can do this:

$("#showNames").text(this.$t('hide_labels'));

if you so choose. Generally it's best to use Vue methods to update the DOM, but this is available to you if you really need it.

Bert
  • 80,741
  • 17
  • 199
  • 164
0

As far as I understand how Vue.js works, it is not posible to parsue vue.js templates directly from jquery. However you have some choices with this problem e.g:

  • call function $("#showNames").text(translate('hide_labels')); where translation function return translation.
  • use {{ $t('hide_labels') }} inside vue.js template (without using jquery)
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345