snackbar with colors, close button text

This commit is contained in:
Jörn-Michael Miehe 2019-05-09 03:31:43 +02:00
parent 066073fa54
commit 0a61d2750b
3 changed files with 22 additions and 20 deletions

View file

@ -5,9 +5,9 @@
</v-btn> </v-btn>
<v-card> <v-card>
<v-snackbar v-model="hasError" :timeout="6000" absolute top> <v-snackbar v-model="snackbar.visible" :timeout="6000" :color="snackbar.color" absolute top>
{{ errorText }} {{ snackbar.text }}
<v-btn fab flat icon @click.native="hasError = false"> <v-btn @click.native="snackbar.visible = false" fab flat icon>
<v-icon>close</v-icon> <v-icon>close</v-icon>
</v-btn> </v-btn>
</v-snackbar> </v-snackbar>
@ -30,7 +30,7 @@
</v-btn> </v-btn>
<v-btn color="error" @click.native="dialog = false"> <v-btn color="error" @click.native="dialog = false">
Cancel Close
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
</v-form> </v-form>
@ -44,8 +44,11 @@ export default {
data: () => ({ data: () => ({
dialog: false, dialog: false,
valid: true, valid: true,
hasError: false, snackbar: {
errorText: '' visible: false,
color: '',
text: ''
}
}), }),
props: { props: {
@ -59,18 +62,16 @@ export default {
} }
}, },
showError(text) { showSnackbar(text, color) {
let actually = () => { if (text == '') return
this.hasError = true
this.errorText = text
}
if (this.hasError) { this.snackbar.visible = false
this.hasError = false
window.setTimeout(actually, 100) window.setTimeout(() => {
} else { this.snackbar.text = text
actually() this.snackbar.color = color
} this.snackbar.visible = true
}, 100)
} }
}, },

View file

@ -55,9 +55,10 @@ export default {
if (response.data.success) { if (response.data.success) {
let cookie_data = JSON.parse(response.data.message) let cookie_data = JSON.parse(response.data.message)
Cookies.set('session', cookie_data.value, cookie_data.properties) Cookies.set('session', cookie_data.value, cookie_data.properties)
this.$refs.main.showSnackbar("Login successful!", 'success')
this.$router.push('about') this.$router.push('about')
} else { } else {
this.$refs.main.showError(response.data.message) this.$refs.main.showSnackbar(response.data.message, 'error')
} }
}) })
} }

View file

@ -75,11 +75,11 @@ export default {
password: this.password password: this.password
}) })
.then(response => { .then(response => {
// this.$refs.form.reset()
console.log('register', response.data) console.log('register', response.data)
if (response.data.success) { if (response.data.success) {
this.$refs.main.showSnackbar("Registration successful!", 'success')
} else { } else {
this.$refs.main.showError(response.data.message) this.$refs.main.showSnackbar(response.data.message, 'error')
} }
}) })
} }