vuebase--8._axios

_axios:

vue----->axios(网络请求)

Axios是一个基于promise的HTTP库,可以用在浏览器和node.js中。

安装

 npm install axios --save

引入:

import axios from ‘axios‘

Vue.prototype.$axios=Axios

实例:

<template lang="html">
<div class="hello">
HelloWorld!
</div>
</template>

<script>
export default {
name: ‘HelloWorld‘,
data() {
return {
msg: ‘Welcome to Your Vue.js App‘
}
},
mounted() {
this.$axios.get("xxxx")
.then(res => {
console.log(res.data)
}).catch(error => {
console.log(error);
})
}
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1,
h2 {
font-weight: normal;
}

ul {
list-style-type: none;
padding: 0;
}

li {
display: inline-block;
margin: 0 10px;
}

a {
color: #42b983;
}
</style>

vuebase--8._axios

上一篇:xamarin.android SurfaceView 实现 游戏 触摸摇杆


下一篇:vuebase--9._axios post请求