1,getList是自己定义的一个方法,fetchList()是获取商品接口的方法,ListQuery是后端的接口,初始值在data(){return{}}中,调用需要用this.
response是响应(响应头,响应行,响应体):1.响应信息,2.状态码,3.响应正文,request是请求
item1()是判断是否又被收藏的接口,里面的参数是一个对象book_id是后端所需要传的参数,e.id是值,e是通过forEach循环获取数组中的每一个对象通过"."添加到数组对象中
getList() {
fetchList(this.listQuery).then((response) => {
console.log(response.data)
this.records = response.data.data.records
this.records.forEach((e) => {
// e.color = '#000000'
item1({ book_id: e.id }).then((response) => {
this.icon7 = response.data.data
if (this.icon7) {
e.color = ' #ee0a24'
e.star = 'star'
console.log(e.star)
} else {
e.star = 'star-o'
// console.log(e.star)
e.color = '#000000'
}
// return this.icon7
})
})
2.forEach语法:
this.arrays.forEach((e) => {
e.XXX="XXXX"
})
3,效果
开始没加这个的时候,点一个其他的跟着一起变,获取不到数据库中原有的那些数据