使用 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);
                
})

 

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