码迷,mamicode.com
首页 > 移动开发 > 详细

vue中简单的数据请求 fetch axios

时间:2019-09-28 12:38:59      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:vue   for   json   地址   eth   etc   ons   post   ade   

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

 

vue中简单的数据请求 fetch axios

标签:vue   for   json   地址   eth   etc   ons   post   ade   

原文地址:https://www.cnblogs.com/skydragonli/p/11602494.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!