* 从 data.json 加载所有可用的课本数据 * @returns {Promise } 课本数据列表
()
| 89 | * @returns {Promise<Array>} 课本数据列表 |
| 90 | */ |
| 91 | async loadBooks() { |
| 92 | if (this.state.books.length) return this.state.books; |
| 93 | |
| 94 | try { |
| 95 | const response = await fetch('data.json'); |
| 96 | const data = await response.json(); |
| 97 | this.state.books = Array.isArray(data.books) ? data.books : []; |
| 98 | return this.state.books; |
| 99 | } catch (error) { |
| 100 | console.error(this.config.ERROR_MESSAGES.LOAD_BOOKS, error); |
| 101 | this.state.books = []; |
| 102 | return []; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * 根据 key 查找课本 |
no outgoing calls
no test coverage detected