Skip to content

Instantly share code, notes, and snippets.

@nelsonmfinda
Created February 5, 2019 20:59
Show Gist options
  • Select an option

  • Save nelsonmfinda/d83d2c22fa2b56ac13c13cb544f32ee8 to your computer and use it in GitHub Desktop.

Select an option

Save nelsonmfinda/d83d2c22fa2b56ac13c13cb544f32ee8 to your computer and use it in GitHub Desktop.
<script>
import axios from 'axios';
export default {
data () {
return {
email: ''
}
},
methods: {
onSubmit () {
axios.post(
'post_url',
{},
{
withCredentials: true,
baseURL: '',
timeout: 10000,
crossDomain: true,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
'Access-Control-Allow-Headers': "Content-type,Accept,X-Access-Token,X-Key",
'X-Requested-With': 'XMLHttpRequest',
},
auth: {
username: '',
password: ''
}
}
)
.then(function (response) {
console.log('response is : ' + response.data);
})
.catch(function (error) {
if (error.response) {
console.log(error.response.headers);
}
else if (error.request) {
console.log(error.request);
}
else {
console.log(error.message);
}
console.log(error.config);
})
}
}
}
</script>
<template>
</template>
<style>
</style>
@acidiney
Copy link
Copy Markdown

acidiney commented Feb 5, 2019

antes do Axios, vamos deixar uma instrução Global...
import axios from 'axios'
axios.defaults.headers.post['Content-Type'] = 'application/json'

@nelsonmfinda
Copy link
Copy Markdown
Author

@acidiney Sim, recebi um token

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