Skip to content

Instantly share code, notes, and snippets.

@victorhugorch
Created May 3, 2017 21:56
Show Gist options
  • Save victorhugorch/ef97078f5d8015fc12230e97daf8a37c to your computer and use it in GitHub Desktop.
Save victorhugorch/ef97078f5d8015fc12230e97daf8a37c 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: []
}
},
created () {
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)
})
},
mounted () {
const apiReq = `url`
// PROBLEMA AQUI
// axios.post(apiReq, {}, { headers: { Authorization: 'INSERIR TOKEN MANUALMENTE AQUI FUNCIONA' } })
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
})
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment