简单aixos实现get和post请求
1.安装aixos -----$ npm install axios
2.引入aixos
<button @click="getHandle">发送get请求</button>
<button @click="postHandle">发送post请求</button>
methods: {
getHandle() {
//axios.get 发起get请求
//参数一表示请求地址
//参数二表示配置信息
// params 表示传递到服务器端的数据,以url参数形式拼接在请求地址后面
// headers 表示请求头
axios
.get("https://api.cat-shop.penkuoer.com/api/v1/products", {
params: {
page: 3,
per: 2,
},
headers: {},
})
.then((res) => console.log(res));
},
postHandle() {
//post请求传递三个参数
//请求地址
//传递的数据 在请求体中传递
//axios默认发送的数据是json格式的
//配置信息
//headers中有content-type:'application/json'默认的
// 登录
axios
.post(
"https://api.cat-shop.penkuoer.com/api/v1/auth/login",
{
use