[Vuejs]-Passing twig data to vue js in symfony 4

0👍

Have you checked the value of this.$el? I suspect that it targets <div id="CookieLaw" data-locale="{{ app.request.locale }}"></div> but in that case the latter element would be replaced by your Vue template.

If that’s the case you should put the data-attribute in an element over it and instead of this.$el.attributes['data-locale'].value you write this.$el.previousElementSibling.getAttribute('data-locale').value

I would like to add also that your lifecycle hook is beforeMount but your element does not still exist at this point; try with mounted()instead

Leave a comment