vuebase--8._axios

Posted xiao-peng-ji

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

Vue axios

认识axios

Xhr

Vue 方法

axios 全攻略之基本介绍与使用(GET 与 POST)

axios 全攻略之基本介绍与使用(GET 与 POST)