fetch 不需要额外的安装什么东西,直接就可以使用
fetch(url, { method:‘post‘, headers: { ‘Content-Type‘: ‘application/x-www-form-urlencoded‘ }, body: "name=kerwin&age=100" }).then(res => res.json()).then(data => {console.log(data)}) ------------------------------------------------------------------------------------- fetch(url, { method:‘post‘, headers: { "Content‐Type": "application/json" }, body: JSON.stringify({ name:"kerwin", age:100 }) }).then(res => res.json()).then(data => {console.log(data)})
axios 必须得安装之后才能使用 cnpm i axios
mounted () { axios.get(‘请求的地址‘) .then(res => { console.log(res.data) }) } ------------------------------------------------------------------------------ mounted () { axios.post(‘请求的地址‘, { username: ‘18813007444‘, password: ‘1234456‘ }).then(res => { console.log(res.data) }) }