- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将成分记录到控制台,但它总是未定义
export default class Recipe {
constructor(ID) {
this.ID = ID;
}
getRicepeById () {
const res = await fetch(`https://www.food2fork.com/api/get?key=${key}&rId=${this.ID}`);
this.title = res.data.recipe.title;
this.image = res.data.recipe.image_url;
this.author = res.data.recipe.publisher;
this.ingredients = res.data.recipe.ingredients;
//this.ingredients = [1, 2, 3, 4, 4, 23, 2];
}
calculateTime() {
const totalIngredients = this.ingredients;
//here is my problem
console.log(totalIngredients)
}
}
最佳答案
getRicepeById
应该是 async
,因为您在此方法的主体中使用了 await
。另外,请确保您在 fetch
完成后调用 calculateTime
关于javascript - 为什么我的 (this.ingredients) 未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58327333/
我试图将成分记录到控制台,但它总是未定义 export default class Recipe { constructor(ID) { this.ID = ID; }
我有兴趣编写一个非常简约的编译器。 我想编写一个满足以下条件的小软件(用 C/C++): 以 ELF 格式输出 (*nix) 输入是一个文本文件 类C语法和句法 没有链接器 没有预处理器 非常小(最多
当我克隆 div 时,我试图仅更改 label 标记。当前的 JS 代码更改了下拉列表中的产品名称。 var clone = $('#product-1').clone(false)[0].outer
嘿,我目前有一个特定的链接列表,其中包含所有可用的成分。 private LinkedList ingredients = new LinkedList(); 成分包含以下值 ingredi
完整的 rails 新手尝试开始。 我有两个类,成分和单元。有三个单位,磅、加仑和几十个,每种成分正好有一个单位。我想我正确设置了关联/路线。 创建新成分时,我需要要求用户从这三个中设置单位。 我用另
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在从《Actions 5th,第 3 章,JDBC 中的 Spring》学习 Spring boot。 我有墨西哥卷饼类(class): @Data public class Taco {
我使用 GoLang v1.5.1,我收到了这个奇怪的错误,或者我错过了一些东西。 在一个名为模型的包中,我定义了以下内容: type SearchResultRow struct { ID
我刚刚开始使用 PHP/MySQL,所以请原谅这个相当简单的问题: 作为练习示例,我想创建一个小型食谱数据库。每个食谱都有 X 种不同的成分。我认为该表非常简单 - 每行代表一个食谱,第一列(主键)之
我是一名优秀的程序员,十分优秀!