Skip to content

Instantly share code, notes, and snippets.

@wesleyguirra
Created June 1, 2017 05:46
Show Gist options
  • Save wesleyguirra/d5661dad5307e32dd4c4ed4365efba46 to your computer and use it in GitHub Desktop.
Save wesleyguirra/d5661dad5307e32dd4c4ed4365efba46 to your computer and use it in GitHub Desktop.
import axios from 'axios'
axios.defaults.baseURL = 'http://localhost:4567/api/v1'
export default {
login ({commit}, credentials) {
return axios.post('login', {
cnpj: credentials.cnpj,
cps: credentials.cps,
password: credentials.password
}, {headers: {usertype: credentials.usertype}})
.then(response => {
commit('LOGIN')
localStorage.setItem('token', response.data.token)
commit('LOGIN_SUCCESS')
return response.data
})
.catch(error => {
return error.response
})
}
}
<template>
// ...
</template>
<script>
// ...
methods: {
handleSubmit (name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.login(this.formValidate).then(() => {
this.$Message.success('Logado com sucesso!')
}).catch(response => { // Aqui eu to tentando usar o catch encadeado
console.log(response.data)
this.$Message.error(response)
})
} else {
this.$Message.error('foram encontrados erros no formulário!')
}
})
},
handleReset (name) {
this.$refs[name].resetFields()
},
...mapActions(['login'])
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment