mirror of
https://github.com/tenrok/vue-form-wizard.git
synced 2026-06-08 13:02:23 +03:00
Move example to dev-example folder
Remove watcher from FormWizard component to avoid double beforeChange trigger Code cleanup
This commit is contained in:
-73
@@ -1,73 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<form-wizard @on-complete="onComplete"
|
||||
shape="circle"
|
||||
color="#e74c3c"
|
||||
class="card">
|
||||
<tab-content title="Personal details"
|
||||
:before-change="validateAsync"
|
||||
icon="ti-user">
|
||||
My first tab content
|
||||
</tab-content>
|
||||
<tab-content title="Additional Info"
|
||||
:before-change="validate"
|
||||
icon="ti-settings">
|
||||
My second tab content
|
||||
</tab-content>
|
||||
<tab-content title="Last step"
|
||||
icon="ti-check">
|
||||
Yuhuuu! This seems pretty damn simple
|
||||
</tab-content>
|
||||
|
||||
</form-wizard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
methods: {
|
||||
onComplete () {
|
||||
alert('Yay!')
|
||||
},
|
||||
validateAsync () {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve(true)
|
||||
}, 1000)
|
||||
})
|
||||
},
|
||||
validate () {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
$border-radius-extreme: 6px !default;
|
||||
$white-color: white;
|
||||
$gray-input-bg: #F3F2EE !default;
|
||||
$card-black-color: #252422 !default;
|
||||
|
||||
body {
|
||||
margin-top: 20px;
|
||||
background-color: #ecf0f1;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
padding: 0px 20px;
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: $border-radius-extreme;
|
||||
box-shadow: 0 2px 2px rgba(204, 197, 185, 0.5);
|
||||
background-color: $white-color;
|
||||
color: $card-black-color;
|
||||
padding: 10px 0;
|
||||
margin-bottom: 20px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -213,8 +213,11 @@
|
||||
this.setLoading(true)
|
||||
promiseFn.then((res) => {
|
||||
this.setLoading(false)
|
||||
if (res) {
|
||||
if (res === true) {
|
||||
callback()
|
||||
this.$emit('validated', true, this.activeTabIndex)
|
||||
} else {
|
||||
this.$emit('validated', false, this.activeTabIndex)
|
||||
}
|
||||
}).catch(() => {
|
||||
this.setLoading(false)
|
||||
@@ -222,7 +225,10 @@
|
||||
// we have a simple function
|
||||
} else {
|
||||
if (promiseFn) {
|
||||
this.$emit('validated', true, this.activeTabIndex)
|
||||
callback()
|
||||
} else {
|
||||
this.$emit('validated', false, this.activeTabIndex)
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -242,11 +248,9 @@
|
||||
let oldTab = this.tabs[oldIndex]
|
||||
let newTab = this.tabs[newIndex]
|
||||
if (oldTab) {
|
||||
oldTab.show = false
|
||||
oldTab.active = false
|
||||
}
|
||||
if (newTab) {
|
||||
newTab.show = true
|
||||
newTab.active = true
|
||||
}
|
||||
this.activeTabIndex = newIndex
|
||||
@@ -280,7 +284,7 @@
|
||||
prevTab () {
|
||||
let cb = () => {
|
||||
if (this.activeTabIndex > 0) {
|
||||
this.activeTabIndex--
|
||||
this.changeTab(this.activeTabIndex, this.activeTabIndex - 1)
|
||||
this.isLastStep = false
|
||||
}
|
||||
}
|
||||
@@ -292,25 +296,18 @@
|
||||
},
|
||||
mounted () {
|
||||
this.tabs = this.$children.filter((comp) => comp.$options.name === 'tab-content')
|
||||
if (this.tabs.length > 0) {
|
||||
if (this.tabs.length > 0 && this.startIndex === 0) {
|
||||
let firstTab = this.tabs[this.activeTabIndex]
|
||||
firstTab.show = true
|
||||
firstTab.active = true
|
||||
}
|
||||
if (this.startIndex < this.tabs.length) {
|
||||
let tabToActivate = this.tabs[this.startIndex]
|
||||
this.activeTabIndex = this.startIndex
|
||||
tabToActivate.active = true
|
||||
this.maxStep = this.startIndex
|
||||
} 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`)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
activeTabIndex: function (newVal, oldVal) {
|
||||
let cb = () => {
|
||||
this.changeTab(oldVal, newVal)
|
||||
}
|
||||
this.beforeTabChange(oldVal, cb)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div v-show="show" class="tab-container">
|
||||
<div v-if="active" class="tab-container">
|
||||
<slot>
|
||||
</slot>
|
||||
</div>
|
||||
@@ -30,7 +30,6 @@
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
show: false,
|
||||
active: false
|
||||
}
|
||||
}
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
// The Vue build version to load with the `import` command
|
||||
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
|
||||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
import FormWizard from './index'
|
||||
Vue.use(FormWizard)
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
/* eslint-disable no-new */
|
||||
new Vue({
|
||||
el: '#app',
|
||||
template: '<App/>',
|
||||
components: {App}
|
||||
})
|
||||
Reference in New Issue
Block a user