R
R
r_g_b_a2020-02-16 16:23:40
Vue.js
r_g_b_a, 2020-02-16 16:23:40

How to display data on click in vue?

In the process of learning the basics of vue, I'm trying to rewrite a jquery script.
There is such an example .
1) Here I tried to make a two-level menu, and now I want the values ​​​​in the lines a , b and the link to the photo to be updated when clicking on its items.
As I understand it, the right solution is to create a new variable in the data object ( active in my example), and store the value of the active menu item in it. To do this, I created the changeCategory method, but I don’t know what to assign in active . And I suspect that my {{active.a}} entry before the first click will throw an error.
2) How can I make the first item of the first menu already selected when the site loads? With jquery I could do something like $(ul ul li).eq(0).click() .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-02-16
@r_g_b_a

<div @click="changeCategory(subcat)">
...
<div v-for="(v, k) in active">{{ k }}: {{ v }}</div>

changeCategory({ a, b }) {
  this.active = { a, b };
},

How can I make the first item of the first menu already selected when the site loads?

created() {
  this.changeCategory(this.categories[0].sub[0]);
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question