尚品汇的后台管理项目中,请求品牌商品列表数据发生以下错误:
但是console.log(this.$API)
却没有问题:
有两种解决方法
【①】用this.$API.default.trademark.reqTradeMarkList(page, limit)
发起请求
async getData() {
const { page, limit } = this
console.log(this.$API);
let result = await this.$API.trademark.reqTradeMarkList(page, limit)
if (result.code == 200) {
this.total = result.data.total
this.list = result.data.records
}
}
【②】在main.js中,修改API的引入方式,依旧使用this.$API.trademark.reqTradeMarkList(page, limit)
发送请求
// 修改前
import * as API from '@/api'
// 修改后
import API from '@/api'
都可以成功得到数据: