Search code examples
jqueryvue.jsvuejs2vue-i18n

Is it possible to parse Vue.js data with jQuery?


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?


Solution

  • 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.