使用 axios 后导致 thinkphp 的 isAjax 一直为false

原因:axios 请求头中没有带 X-Requested-With 这个参数。

 

解决办法:

给请求头添加 X-Requested-With 这个参数,参数值为 XMLHttpRequest

// 以 axios 为例

this.$axios.get('http://yourdomain.com/api/getMenus', 
{
    headers: {'X-Requested-With': 'XMLHttpRequest'}

}).then((res)=>{
                
    // console.log(res.data);
                
})

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章