框架级的数据请求
- axios ( 第三方库 — 别人封装好的库 )
- fetch ( javascript 原生提供 )
- vue数据请求的发展
- vue-resource ( Vue 以前自己封装使用的请求类库 ) ,但是 vue-resource作者已经放弃更新了
- vue-resource 作者推荐我们使用 axios
- vue-resource 用法 和 axios 相似度 90% +
- vue2.0我们基本上使用的都是 fetch / axios
- vue-resource 是有jsonp的
- vue-resource 如果在vue中使用,是挂载当前的 实例( 组件 ) 的$http属性身上的
- 举例 this. h t t p ( o p t i o n s ) t h i s . http( options ) this. http(options)this.http.get() this.$http.post
- axios 和 fetch 没有jsonp 数据请求类型的
- axios 和 fetch 都是promise
- axios会对我们请求来的结果进行再一次的封装( 让安全性提高 )
- axios案例:
new Vue({
el: '#app',
methods: {
getData () {
axios({
url: './data/data.json',
method: 'get',
})
.then( res => console.log( res ))
.catch( error => conosle.log( error ))
},
postData () {
},
get_myself_php_data () {
axios({
url: 'http://localhost/get.php',
params: {
a: 1,
b: 2
}
})
.then( res => console.log( res ))
.catch( error => console.log( error ))
},
get_be_data () {
axios({
url: 'https://m.maizuo.com/gateway',
headers: {
'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"154549400038873748996477"}',
'X-Host':</