axios跨域及封装
1、安装
npm install axios --save
2、main.js引用
import axios from 'axios';
3、axios基本用法
function get(){
//axios.get('http://localhost:3000/post?id=1')
axios({
url:'/posts',
param:{
id:1
}
})
.then(response => {
console.log('/posts get',response.data)
})
.catch(error => {
console.log('error',error.message)
})
}
function post(){
// axios.post('http://localhost:3000/post',{"title":"json-server3"})
axios({
url:'/post',
methods;'post',
data:{"title":"json-server3"}
})
.then(response => {
console.log('/posts pos