I want to achieve this active link on my div element here you can see the example that i want to do with my code
http://jsfiddle.net/fiddleyetu/9ff79/
JavaScript
x
7
1
$(function() {
2
$( 'ul.nav li' ).on( 'click', function() {
3
$( this ).parent().find( 'li.active' ).removeClass( 'active' );
4
$( this ).addClass( 'active' );
5
});
6
});
7
in here using vue.js i can’t do the active link on my div elements
here is my code for the elements on which i have to do the links active
JavaScript
1
19
19
1
<div class="conversion">
2
<div class="file has-text-centered icon-active-color" v-on:click="activeiconc">
3
<img src="../imgs/png.png"/>
4
<h4>.PNG</h4>
5
</div>
6
<div class="file has-text-centered" v-on:click="activeicon" v-bind:class="{ 'icon-active-color':activeiconc,}">
7
<img src="../imgs/pdf.png"/>
8
<h4>.PDF</h4>
9
</div>
10
<div class="file has-text-centered" v-on:click="activeicon" v-bind:class="{ 'icon-active-color':activeiconc }">
11
<img src="../imgs/jpg.png"/>
12
<h4>.JPG</h4>
13
</div>
14
<div class="file has-text-centered" v-on:click="activeicon" v-bind:class="{ 'icon-active-color':activeiconc }">
15
<img src="../imgs/psd.png"/>
16
<h4>.PSD</h4>
17
</div>
18
</div>
19
js
JavaScript
1
43
43
1
export default {
2
components: {
3
MainLayout
4
},
5
data: function(){
6
return {
7
logo: false,
8
color:false,
9
list:true,
10
grid:false,
11
deletebtn:false,
12
isImageModalActive: false,
13
activerow: false,
14
activeiconc:false,
15
}
16
},
17
methods:{
18
19
showgrid:function(){
20
this.grid = true;
21
this.list = false;
22
23
},
24
showlist:function(){
25
this.list ^=true;
26
this.grid = false
27
},
28
showLogo:function(){
29
this.logo ^= true;
30
this.color = false;
31
this.deletebtn ^= true;
32
this.activerow ^= true
33
},
34
showColor:function(){
35
this.color ^= true;
36
this.logo = false;
37
},
38
activeicon:function(){
39
this.activeiconc ^= true;
40
}
41
}
42
}
43
Advertisement
Answer
I’m new to Vue but an easy way to turn your JQuery example into Vue.js is this: Jsfiddle demo
Basically, you need to store the active element in your Vue data, and set the class based on in. You could use a v-for
to render the list.
The HTML
part:
JavaScript
1
8
1
<div id="app">
2
<ul>
3
<li @click="activate(1)" :class="{ active : active_el == 1 }">Link 1</li>
4
<li @click="activate(2)" :class="{ active : active_el == 2 }">Link 2</li>
5
<li @click="activate(3)" :class="{ active : active_el == 3 }">Link 3</li>
6
</ul>
7
</div>
8
The Vue.js
:
JavaScript
1
12
12
1
var app = new Vue({
2
el:"#app",
3
data:{
4
active_el:0
5
},
6
methods:{
7
activate:function(el){
8
this.active_el = el;
9
}
10
}
11
});
12