我的服务中有一个方法,该方法从JSON获取YouTube频道列表 然后在组件文件中,我使用此方法,但返回错误
以下使用的代码摘自有效的上一个项目
service.js
export default class ChannelService {
constructor(){}
async makeRequest(url) {
const response = await fetch(url);
//console.log(response);
return await response.json();
}
async getChannels() {
const url = `../src/assets/channels.json`;
return this.makeRequest(url);
}
}
component.js
import MyComponent from '../shared/my-component.js';
import ChannelService from '../services/channel.service.js';
export default class ChannelListComponent extends MyComponent{
template() {
return `
<h1>Channel list data</h1>
`;
}
async render(...args) {
super.render(...args);
const allChannels = ChannelService.getChannels();
console.log(allChannels);
}
}
我想调用getChannels方法并列出频道,但出现错误,提示该方法不起作用