其他分享
首页 > 其他分享> > vue小项目普通的小项目 怎样去 使用axios去进行ajax请求数据 cdn引用 qs

vue小项目普通的小项目 怎样去 使用axios去进行ajax请求数据 cdn引用 qs

作者:互联网

vue小项目普通的小项目 怎样去 使用axios去进行ajax请求数据

小项目的话就引用线上的ajax就好了

引用地址 https://unpkg.com/axios/dist/axios.min.js 并且还要引用qs地址是
https://cdn.bootcss.com/qs/6.7.0/qs.min.js

//将这引入页面即可
<script type="text/javascript" src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/qs/6.7.0/qs.min.js"></script>

js使用-----post

//将这引入页面即可
var qs = Qs
//设置请求头
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

axios.post('https://tool.eztao.net/api/AdminLogs',
//请求参数
qs.stringify({
	logType:0,
	content:this.content
	})
)
.then(function (response) {
	console.log(response)
})
.catch(function (error) {
	console.log(error)
})

get请求

//将这引入页面即可

//请求数参数
var data = {
	page:number,
	pagesize:20
}
var that = this
axios.get('https://tool.eztao.net/api/AdminLogs?key=',
//参数
{params: data}
)
  .then(function (response) {
	that.people = response.data.list
	that.all = response.data.totalCount
  })
  .catch(function (error) {
	console.log(error)
  })

标签:function,qs,axios,cdn,https,data,response
来源: https://blog.csdn.net/weixin_44291886/article/details/122218467