axios教程

时间:2018-12-18 01:54:51   收藏:0   阅读:198
一、简介
1、axios是基于Promise,用于浏览器(script标签引入)和nodejs的,与服务端进行通信的库
2、特征:

二、使用
1、在需要的模块中引入使用:
import axios from ‘axios‘
2、语法:

三、案例

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>
<script>
    import axios from ‘axios‘
export default {
  name: ‘HelloWorld‘,
  data () {
    return {
      msg: ‘Welcome to Your Vue.js App‘
    }
  },
  created(){
    /*axios.get(‘https://www.easy-mock.com/mock/5c1767c06ccaa7461ef01ee9/example/dataList‘,{
        params:{
            name:‘xiao‘,
                age:‘20‘
        }
    })
    .then((response)=>{
        console.log(response.data)
    })
    .catch((error)=>{
        console.log(error)
    })*/
        //发送给后端的数据附在url的?后面
        //Request URL:https://www.easy-mock.com/mock/5c1767c06ccaa7461ef01ee9/example/dataList?name=xiao

    axios.post(‘https://www.easy-mock.com/mock/5c1767c06ccaa7461ef01ee9/example/postData‘,{
            name:‘xiao‘  
        })
    .then((response)=>{
        console.log(response.data)
    })
    .catch((error)=>{
        console.log(error)
    })
  }
}
////数据是隐藏的,不会显示出来,放在Request Payload {name:‘xiao‘}
</script>

原文:http://blog.51cto.com/9161018/2331694

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!