-
-
Save DawTaylor/45dbe79b461455af3ae50da104ba627b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import Vue from 'vue' | |
import axios from 'axios' | |
import VueAxios from 'vue-axios' | |
const qs = require('qs') | |
Vue.use(VueAxios, axios) | |
export default { | |
name: 'home', | |
data () { | |
return { | |
token: '', | |
errors: [], | |
data: [], | |
id: [], | |
solicitacao: [], | |
status: [] | |
} | |
}, | |
methods : { | |
getToken() { | |
const apiAuth = `url` | |
axios.post(apiAuth, qs.stringify({ | |
client_id: '' , | |
client_secret: '', | |
email: '', | |
password: '' | |
})).then(response => { | |
this.token = 'Bearer ' + response.data.token | |
}).catch(e => { | |
this.errors.push(e) | |
}) | |
}, | |
getOutraCoisa() { | |
const apiReq = `url` | |
axios.post(apiReq, {}, { headers: { Authorization: this.token } }) | |
.then(response => { | |
console.log(response.data) | |
}) | |
.catch(e => { | |
this.errors.push(e) | |
console.log(e, this.token) // TOKEN CHEGA AQUI | |
}) | |
} | |
}, | |
mounted() { | |
this.getToken() | |
}, | |
watch : { | |
// Quando o valor de this.token mudar, vai disparar a nova request | |
token : function() { | |
this.getOutraCoisa() | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Valeu pela força, Adalberto. 😀