_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>