R
R
RudMa2021-12-21 08:45:15
Vue.js
RudMa, 2021-12-21 08:45:15

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="">


while I'm accessing through the DOM

sessid: document.querySelector("#app-cart").getAttribute("data-sessid")


How to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2021-12-21
@RudMa

this.$el.dataset.sessid
Or, from a deeper sub-component
this.$root.$el.dataset.sessid

S
samorez999, 2021-12-21
@samorez999

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 question

Ask a Question

731 491 924 answers to any question