Skip to content

Commit e4d2f6f

Browse files
committed
Fix v-model not working
1 parent 49358cb commit e4d2f6f

File tree

6 files changed

+32
-38
lines changed

6 files changed

+32
-38
lines changed

dev/App.vue

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,16 @@
22
<div>
33
<vue-tabs class="card" @on-error="handleError"
44
v-model="tabName">
5-
<!--<template slot="tab" scope="props">
6-
<li :class="{active:props.tab.active}" >
7-
<a href="" @click.prevent="props.clickHandler(props.index)" style="border-radius:50%">
8-
{{props.tab.title}}
9-
</a>
10-
</li>
11-
</template>-->
12-
<v-tab v-for="(re, index) in reList"
13-
:key="re.name"
14-
:title="re.name"
5+
<v-tab v-for="(tab, index) in tabList"
6+
:key="tab.name"
7+
:title="tab.name"
158
icon="ti-user">
16-
{{re.name}}
9+
{{tab.name}}
1710
</v-tab>
1811
</vue-tabs>
19-
<button @click="reList.push({name:'test'})">Add more!</button>
20-
<button @click="reList.splice(0,1)">Remove first</button>
12+
<button @click="tabList.push({name:'test'})">Add more!</button>
13+
<button @click="tabList.splice(0,1)">Remove first</button>
14+
<button @click="goToSecondTab">Go to second tab</button>
2115
</div>
2216
</template>
2317

@@ -27,17 +21,17 @@
2721
name: 'app',
2822
data(){
2923
return {
30-
reList : [],
31-
tabName: 'name2'
24+
tabList : [{name:'name1'},{name:'name2'},{name:'name3'}],
25+
tabName: 'name1'
3226
}
3327
},
3428
methods: {
3529
handleError(error){
3630
this.error = error
31+
},
32+
goToSecondTab(){
33+
this.tabName='name2'
3734
}
38-
},
39-
mounted () {
40-
this.reList = [{name:'name1'},{name:'name2'},{name:'name3'}]
4135
}
4236
}
4337
</script>

dist/vue-tabs.common.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ var VueTabs = {
110110
}
111111
return [];
112112
},
113-
findTabAndActivate: function findTabAndActivate(tabName) {
114-
var indexToActivate = this.tabs.findIndex(function (tab) {
115-
return tab.title === tabName;
113+
findTabAndActivate: function findTabAndActivate(tabNameOrIndex) {
114+
var indexToActivate = this.tabs.findIndex(function (tab, index) {
115+
return tab.title === tabNameOrIndex || index === tabNameOrIndex;
116116
});
117117
if (indexToActivate != -1) {
118118
this.changeTab(this.activeTabIndex, indexToActivate);
@@ -237,10 +237,10 @@ var VueTabs = {
237237
if (newList.length > 0 && this.value) {
238238
this.findTabAndActivate(this.value);
239239
}
240+
},
241+
value: function value(newVal) {
242+
this.findTabAndActivate(newVal);
240243
}
241-
},
242-
value: function value(newVal) {
243-
this.findTabAndActivate(newVal);
244244
}
245245
};
246246

dist/vue-tabs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ var VueTabs = {
112112
}
113113
return [];
114114
},
115-
findTabAndActivate: function findTabAndActivate(tabName) {
116-
var indexToActivate = this.tabs.findIndex(function (tab) {
117-
return tab.title === tabName;
115+
findTabAndActivate: function findTabAndActivate(tabNameOrIndex) {
116+
var indexToActivate = this.tabs.findIndex(function (tab, index) {
117+
return tab.title === tabNameOrIndex || index === tabNameOrIndex;
118118
});
119119
if (indexToActivate != -1) {
120120
this.changeTab(this.activeTabIndex, indexToActivate);
@@ -239,10 +239,10 @@ var VueTabs = {
239239
if (newList.length > 0 && this.value) {
240240
this.findTabAndActivate(this.value);
241241
}
242+
},
243+
value: function value(newVal) {
244+
this.findTabAndActivate(newVal);
242245
}
243-
},
244-
value: function value(newVal) {
245-
this.findTabAndActivate(newVal);
246246
}
247247
};
248248

dist/vue-tabs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)