Answer the question
In order to leave comments, you need to log in
How to access vue.js root element attributes?
I need to get the attribute values from the root element
<div id="app-cart" data-url="http://localhost:3000/products" data-sessid="sessid" data-link-catalog="catalog.html" data-link-index-page="index.html" data-submit-message="Ваша заявка успешно отправлена!<br> В течение 5 минут мы Вам перезвоним" data-params="">
sessid: document.querySelector("#app-cart").getAttribute("data-sessid")
Answer the question
In order to leave comments, you need to log in
this.$el.dataset.sessid
Or, from a deeper sub-component
this.$root.$el.dataset.sessid
It is correct to work with elements through the associated data, and not with the DOM directly. Like this:
<div id="app-cart" ref="app-cart"></div>
this.$refs.app-cart
More details in the spec
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question