axios與mockjs的奇妙bug

今天在作先後端分離項目的時候,我用mock對同一個url進行get和post兩個攔截,進行不一樣的請求操做(get查找,post增長)ios

而後get沒有問題,但POST死活攔截不了,老是404,因而我單獨搞個小demo測試一下,結果發現了這個奇妙的bug。axios

異常代碼:後端

mockjs.mock('/search', 'POST',{
    'list': [
        { name: '2xxxx', title: '4yyyy' },
        { name: '1xxxx', title: '3yyyy' },
        { name: '2xxxx', title: '7yyyy' },
    ]
})

//axios請求
Axios.post('/search').then(res => {promise

debugger
        console.log(res)
        dispatch(decrement1(number))
    })
結果:Uncaught (in promise) Error: Request failed with status code 404

緣由:mock裏添加POST問題,**要改爲小寫**


* * *


其餘成功:
測試1:

mockjs.mock('/search', 'get',{前後端分離

'list': [
    { name: '2xxxx', title: '4yyyy' },
    { name: '1xxxx', title: '3yyyy' },
    { name: '2xxxx', title: '7yyyy' },
]

})post

//axios代碼:

Axios.get('/search').then(res => {測試

console.log(res)
    })
結果:控制檯正常輸入

等等等,再也不演示了


總結:mockjs傳請求類型是必定要用小寫,get,post。
相關文章
相關標籤/搜索