import { http } from '@kit.NetworkKit';
import { BusinessError } from '@kit.BasicServicesKit';
let select: string[] = ["全部", "华语男", "华语女", "华语组合", "日韩男", "日韩女", "日韩组合", "欧美男", "欧美女", "欧美组合", "其他"];
@Entry
@Component
struct Index {
@State singerList: ESObject[] = [];
@State page: number = 1;
aboutToAppear(): void {
this.getData(this.page);
}
async getData(page: number) {
let httpObj = http.createHttp();
// 使用完整的 URL
let res = await httpObj.request(`https://kuwo.cn/api/www/artist/artistInfo?category=0&pn=${page}&rn=60`, {
header: {
platformtype: "h5",
Referer: "https://kuwo.cn/"
},
expectDataType: http.HttpDataType.OBJECT,
method: http.RequestMethod.GET,
});
console.log(res.result["data"].artistList[1].name)
this.singerList = res.result["data"].artistList;
httpObj.destroy();
}
build() {
Tabs({ barPosition: BarPosition.End }) {
TabContent() {
Column({ space: 5 }) {
ForEach(this.singerList, (item: ESObject) => {
Text(item.name)
})
}
}
.tabBar('歌手')
TabContent() {
}
.tabBar('蘑菇宠医')
}
}
}
// import { http } from '@kit.NetworkKit';
// import { BusinessError } from '@kit.BasicServicesKit';
//
//
//
// let page:number=1;
// let select:string[]=["全部","华语男","华语女","华语组合","日韩男","日韩女","日韩组合","欧美男","欧美女","欧美组合","其他"]
// @Entry
// @Component
// struct Index {
// @State singerList:ESObject[]=[]
//
// @State page:number=1;
// aboutToAppear(): void {
// this.getData(this.page);
// }
// async getData(page:number) {
// let httpObj = http.createHttp();
// let res = await httpObj.request("https://kuwo.cn/api/www/artist/artistInfo?category=0&pn=${page}&&rn=60?page=", {
// header: {
// platformtype: "h5"
// },
// expectDataType: http.HttpDataType.OBJECT,
// method: http.RequestMethod.GET,
// });
// this.singerList=res.result["data"].artistList
//
// httpObj.destroy();
// }
//
//
//
// build() {
// Tabs({ barPosition: BarPosition.End }) {
// TabContent() {
// Column(){
// ForEach(this.singerList,(item:ESObject)=>{
// Text(item.aartist)
// })
// }
// }
// .tabBar('歌手')
//
// TabContent() {
//
// }
// .tabBar('蘑菇宠医')
//
//
// }
// }
// }
在鸿蒙开发中,为什么我请求不到数据
最新发布