解决报错:axios is not defined,以及axios获取数据
axios
·
解决方法一:
1.使用npm安装axios:
npm install --save axios
2.在使用的页面定义:
const axios = require('axios');
注意:定义在export default外
3.使用
带请求头的写法:
getList() {
axios({
methods: "get",
url: "http://baos.greatgroup.cloud:8082/api/v1/patrolPlans",
headers: {
Authorization:
"Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzdXBlciIsImNyZWF0ZWQiOjE2ODA4MzEzMTkyMjIsImV4cCI6MTY4MTQzNjExOX0.eeGwbzNbGuzG9Sxe-TldnufhHJjRnPdNedmXNgCgZm0ZHOd2su-pyALrXxEOlzMaIjYrxtyBNeD7XrGnb-LGlg",
},
})
.then((res) => {
// console.log(res.data.content);
this.dataList = res.data.content;
console.log(this.dataList);
})
.catch((err) => {
console.log(err);
});
},
带参数的写法:
created() {
const _this = this
axios.get('http://localhost:8181/book/findAll/0/6').then(function(resp){
console.log(resp);
_this.tableData = resp.data.content
_this.pageSize = resp.data.size
_this.total = resp.data.totalElements
})
}
若还是报错,axios加上this,即this.axios.get(…)
另:axios详细用法见收藏
更多推荐
已为社区贡献2条内容
所有评论(0)