mirror of
https://github.com/tenrok/vue-form-wizard.git
synced 2026-06-24 00:10:33 +03:00
Support vue-router integration
This commit is contained in:
+4
-4
@@ -5,18 +5,18 @@
|
|||||||
color="#e74c3c"
|
color="#e74c3c"
|
||||||
class="card">
|
class="card">
|
||||||
<tab-content title="Personal details"
|
<tab-content title="Personal details"
|
||||||
|
route="first"
|
||||||
icon="ti-user">
|
icon="ti-user">
|
||||||
My first tab content
|
|
||||||
</tab-content>
|
</tab-content>
|
||||||
<tab-content title="Additional Info"
|
<tab-content title="Additional Info"
|
||||||
|
route="second"
|
||||||
icon="ti-settings">
|
icon="ti-settings">
|
||||||
My second tab content
|
|
||||||
</tab-content>
|
</tab-content>
|
||||||
<tab-content title="Last step"
|
<tab-content title="Last step"
|
||||||
|
route="third"
|
||||||
icon="ti-check">
|
icon="ti-check">
|
||||||
Yuhuuu! This seems pretty damn simple
|
|
||||||
</tab-content>
|
</tab-content>
|
||||||
|
<router-view></router-view>
|
||||||
</form-wizard>
|
</form-wizard>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
+15
@@ -1,12 +1,27 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
import VueRouter from 'vue-router'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import FormWizard from './../src/index'
|
import FormWizard from './../src/index'
|
||||||
|
const First = { template: '<div>First</div>' }
|
||||||
|
const Second = { template: '<div>Second</div>' }
|
||||||
|
const Third = { template: '<div>Third</div>' }
|
||||||
|
|
||||||
|
const router = new VueRouter({
|
||||||
|
mode: 'history',
|
||||||
|
routes: [
|
||||||
|
{ path: '/first', component: First },
|
||||||
|
{ path: '/second', component: Second },
|
||||||
|
{ path: '/third', component: Third }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
Vue.use(VueRouter)
|
||||||
Vue.use(FormWizard)
|
Vue.use(FormWizard)
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
new Vue({
|
new Vue({
|
||||||
|
router,
|
||||||
el: '#app',
|
el: '#app',
|
||||||
template: '<App/>',
|
template: '<App/>',
|
||||||
components: {App}
|
components: {App}
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+2
-1
@@ -25,7 +25,6 @@
|
|||||||
"url": "https://github.com/cristijora/vue-form-wizard"
|
"url": "https://github.com/cristijora/vue-form-wizard"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vue": "^2.2.2",
|
|
||||||
"autoprefixer": "^6.7.2",
|
"autoprefixer": "^6.7.2",
|
||||||
"babel-core": "^6.22.1",
|
"babel-core": "^6.22.1",
|
||||||
"babel-eslint": "^7.1.1",
|
"babel-eslint": "^7.1.1",
|
||||||
@@ -84,7 +83,9 @@
|
|||||||
"sinon-chai": "^2.8.0",
|
"sinon-chai": "^2.8.0",
|
||||||
"stats-webpack-plugin": "^0.6.0",
|
"stats-webpack-plugin": "^0.6.0",
|
||||||
"url-loader": "^0.5.8",
|
"url-loader": "^0.5.8",
|
||||||
|
"vue": "^2.2.2",
|
||||||
"vue-loader": "^11.1.4",
|
"vue-loader": "^11.1.4",
|
||||||
|
"vue-router": "^2.4.0",
|
||||||
"vue-style-loader": "^2.0.0",
|
"vue-style-loader": "^2.0.0",
|
||||||
"vue-template-compiler": "^2.2.4",
|
"vue-template-compiler": "^2.2.4",
|
||||||
"webpack": "^2.2.1",
|
"webpack": "^2.2.1",
|
||||||
|
|||||||
@@ -17,12 +17,13 @@
|
|||||||
<div class="icon-circle" :class="{checked:isChecked(index),square_shape:isStepSquare, tab_shape:isTabShape}"
|
<div class="icon-circle" :class="{checked:isChecked(index),square_shape:isStepSquare, tab_shape:isTabShape}"
|
||||||
:style="isChecked(index)? stepCheckedStyle : {}">
|
:style="isChecked(index)? stepCheckedStyle : {}">
|
||||||
<transition :name="transition" mode="out-in">
|
<transition :name="transition" mode="out-in">
|
||||||
<div v-if="tab.active" class="icon-container" :class="{square_shape:isStepSquare, tab_shape:isTabShape}" :style="tab.active ? iconActiveStyle: {}">
|
<div v-if="tab.active" class="icon-container" :class="{square_shape:isStepSquare, tab_shape:isTabShape}"
|
||||||
|
:style="tab.active ? iconActiveStyle: {}">
|
||||||
<i v-if="tab.icon" :class="tab.icon" class="icon"></i>
|
<i v-if="tab.icon" :class="tab.icon" class="icon"></i>
|
||||||
<i v-else class="icon">{{index+1}}</i>
|
<i v-else class="icon">{{index + 1}}</i>
|
||||||
</div>
|
</div>
|
||||||
<i v-if="!tab.active && tab.icon" :class="tab.icon" class="icon"></i>
|
<i v-if="!tab.active && tab.icon" :class="tab.icon" class="icon"></i>
|
||||||
<i v-if="!tab.active && !tab.icon" class="icon">{{index+1}}</i>
|
<i v-if="!tab.active && !tab.icon" class="icon">{{index + 1}}</i>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
<span class="stepTitle" :style="tab.active ? stepTitleStyle : {}">
|
<span class="stepTitle" :style="tab.active ? stepTitleStyle : {}">
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<span @click="prevTab" v-if="displayPrevButton">
|
<span @click="prevTab" v-if="displayPrevButton">
|
||||||
<slot name="prev">
|
<slot name="prev">
|
||||||
<button type="button" class="btn btn-default btn-wd" :style="fillButtonStyle">
|
<button type="button" class="btn btn-default btn-wd" :style="fillButtonStyle">
|
||||||
{{backButtonText}}
|
{{backButtonText}}
|
||||||
</button>
|
</button>
|
||||||
</slot>
|
</slot>
|
||||||
@@ -218,8 +219,14 @@
|
|||||||
}
|
}
|
||||||
this.activeTabIndex = newIndex
|
this.activeTabIndex = newIndex
|
||||||
this.checkStep()
|
this.checkStep()
|
||||||
|
this.tryChangeRoute(newTab)
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
tryChangeRoute (tab) {
|
||||||
|
if (this.$router && tab.route) {
|
||||||
|
this.$router.push(tab.route)
|
||||||
|
}
|
||||||
|
},
|
||||||
checkStep () {
|
checkStep () {
|
||||||
if (this.activeTabIndex === this.tabCount - 1) {
|
if (this.activeTabIndex === this.tabCount - 1) {
|
||||||
this.isLastStep = true
|
this.isLastStep = true
|
||||||
@@ -263,10 +270,12 @@
|
|||||||
let firstTab = this.tabs[this.activeTabIndex]
|
let firstTab = this.tabs[this.activeTabIndex]
|
||||||
firstTab.show = true
|
firstTab.show = true
|
||||||
firstTab.active = true
|
firstTab.active = true
|
||||||
|
this.tryChangeRoute(firstTab)
|
||||||
}
|
}
|
||||||
if (this.startIndex < this.tabs.length) {
|
if (this.startIndex < this.tabs.length) {
|
||||||
this.activeTabIndex = this.startIndex
|
this.activeTabIndex = this.startIndex
|
||||||
this.maxStep = this.startIndex
|
this.maxStep = this.startIndex
|
||||||
|
this.tryChangeRoute(this.tabs[this.startIndex])
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Prop startIndex set to ${this.startIndex} is greater than the number of tabs - ${this.tabs.length}. Make sure that the starting index is less than the number of tabs registered`)
|
console.warn(`Prop startIndex set to ${this.startIndex} is greater than the number of tabs - ${this.tabs.length}. Make sure that the starting index is less than the number of tabs registered`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
*/
|
*/
|
||||||
beforeChange: {
|
beforeChange: {
|
||||||
type: Function
|
type: Function
|
||||||
|
},
|
||||||
|
route: {
|
||||||
|
type: [String, Object]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
|||||||
Reference in New Issue
Block a user