header('Access-Control-Allow-Origin: *'); header("Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept"); header('Access-Control-Allow-Methods: POST,GET');
在router/router.php頭上寫上上面的header頭就可以正常調用了。
使用 axios 后導致 thinkphp 的 isAjax 一直為false;
解決辦法:
給請求頭添加 X-Requested-With 這個參數,參數值為 XMLHttpRequest
// 以 axios 為例 this.$axios.get('http://yourdomain.com/api/getMenus', { headers: {'X-Requested-With': 'XMLHttpRequest'} }).then((res)=>{ // console.log(res.data); })