vue-resource请求
1.引入vue.js文件
2.引入vue-resourse文件
3.写入与data、methods平级的created()中
const vm = new Vue({
el: '#app',
data: {
imgSrc: ''
},
methods: {
},
created() {
this.$http.get('http://wkt.shangyuninfo.cn/weChat/applet/course/banner/list?number=1').then(
res => {
console.log(res);
this.imgSrc = res.body.data[0].imgUrlPc
}
)
this.$http.post('http://wkt.shangyuninfo.cn/weChat/applet/course/list/type', {
type: 'free',
pageSize: 10,
pageNum: 1
}, { emulateJSON: true }).then(res => {
console.log(res);
})
}
})
axios请求
1.把vue-resource请求中的this.$http 改为 axios
2.post请求中对于不是JSON格式的请求头:
1.let url = new FormData()
2.let url = new URLSearchParams()
url.append('type', 'free')
url.append('pageSize', 5)
url.append('pageNum', 1)