Update:
You can access the attributes of an element by the $refs variable. This is a great way to get information from nested components, since you have access to the children
attribute of the element. (see here)
However, adding the ref
attribute will not work for your example with the v-if
because when v-if
is false it removes the entire element.
Plus, there would be issues of synchronization with the $refs variable and the creation of the element. Here is more on lifecycle hooks).
<button @click="$event => $forceUpdate()">update me</button>
<kpi ref="MyKpi" title="some_kpi">{{ $refs.MyKpi?.title }}</kpi>
This show how on render $refs.MyKpi
does not exist because the element has not been rendered. but when you force the DOM to update. you can see that we do have access to the attributes in the kpi element.
The $refs
variable gives you flexibility for more complex operations on attributes of elements.