0
点赞
收藏
分享

微信扫一扫

axios安装与基本方法

老牛走世界 2022-02-02 阅读 76

安装:

1.npm安装:

npm install axios

2.在主入口文件main.js中引用:

import axios from 'axios'

Vue.use(axios);

3.在组件文件中的methods里使用:

getNewsList(){
      this.axios.get('api/getNewsList').then((response)=>{
        this.newsList=response.data.data;
      }).catch((response)=>{
        console.log(response);
      })
}

方法:1.get请求:直接从后台获取数据,参数写在地址(url)里,第一个参数是url(API的一个地址,由后端提供);

2.post请求:一般在填写表单并提交时,要将输入的数据写在数据库里,参数一般放在对象中;

举报

相关推荐

0 条评论