23、Vue-axios基本使用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>行找的皮卡丘</title>
</head>
<body>
<div id="app"></div>
</body>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="./node_modules/axios/dist/axios.js"></script>
<script type="text/javascript">
Vue.prototype.$axios = axios;
var App={
template:`
<div>
<button @click='senAjax'>发起请求</button>
</div>
`,
methods:{
senAjax(){
this.$axios.get('http://127.0.0.1:8888/')
.then(res=>{
console.log(res);
})
.catch(err=>{
console.log(err)
})
}
}
};
new Vue({
el:'#app',
data(){
return {
}
},
template:`<App/>`,
components:{
App
}
});
</script>
</html>