Skip to content

Instantly share code, notes, and snippets.

@DawTaylor
Forked from victorhugorch/Home.vue
Last active May 3, 2017 23:18
Show Gist options
  • Save DawTaylor/45dbe79b461455af3ae50da104ba627b to your computer and use it in GitHub Desktop.
Save DawTaylor/45dbe79b461455af3ae50da104ba627b to your computer and use it in GitHub Desktop.
<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>
@victorhugorch
Copy link

Valeu pela força, Adalberto. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment