VUE

    技术2022-07-12  78

    1、npm 安装axios,文件根目录下安装,指令如下:

    npm install --save-dev axios

    2、在main.js中引入axios

    import axios from 'axios';

    3、全局配置baseURL(后面如果接口baseURL更改了,可直接修改这里就可以了) main.js文件

    axios.defaults.baseURL = 'http://...';

    4、接着将axios改写为Vue的原型属性 main.js文件

    Vue.prototype.$http = axios;

    页面使用:

    this.$http.get('/') .then(res=>{ console.log(res) }) .catch(err=>{ console.log(err) })
    Processed: 0.012, SQL: 10