Answer the question
In order to leave comments, you need to log in
How to output data from data attribute to vue.js text?
Hello! I'm trying to get the value of the data attribute by clicking on a div block. While it turned out to be displayed in the console.
How to apply the given data_percent variable in the h1 heading of the page. Or in general how such data is transferred to the text of the page.
Code link (PS Turn on the console at the bottom)
Answer the question
In order to leave comments, you need to log in
No attributes need to be touched in this case, and they are not needed.
We add two properties to data - possible values, and the selected value:
data: () => ({
selectedPercent: null,
percents: [ 30, 40, 50 ],
...
}),
<div v-for="p in percents" @click.prevent="selectedPercent = p">
...
computed: {
header() {
return this.selectedPercent !== null ? this.selectedPercent : 'hello, world!!';
},
},
<h1>{{ header }}</h1>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question