axios baseURL的使用方法

tp5.1

namespace app\index\controller;
header('Access-Control-Allow-Origin:*');
use think\Controller;
use think\facade\Request;
class Index extends Controller
{
    public function message()
    {
        $data = Request::param();
        return json_encode($data);
    }
}

main.js

import axios from 'axios'
import qs from 'qs'

Vue.prototype.axios=axios.create({
  baseURL:'http://test.io/index.php/index/index/',
  transformRequest: [//对数据转换成类似get传参的模式
    data => qs.stringify(data)
  ]})

template.vue

mounted(){
    this.axios.post('message',{name:321})
    .then(res=>{console.log(res);})
  }

 

你可能感兴趣的:(vue,axios)