vue中简单的数据请求 fetch axios

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)
        })
    }

 

posted @ 2019-09-28 12:07  LC蜗牛  阅读(585)  评论(0编辑  收藏  举报