首先安装axios:
cnpm install axios -save
安装成功后,在main.js页面引用:
import axios from 'axios'
import Qs from 'qs'
Vue.prototype.axios = axios; //全局注册,使用方法为:this.axios
Vue.prototype.qs = qs; //全局注册,使用方法为:this.qs
使用:
<script> import $ from 'jquery' export default { mounted:function(){ this.axios({ url:'http://localhost:8000/md_tast/news_index', method:'get', responseType:"json" }) .then(function(obj){ console.log(obj) } }) } } </script>