Reactjs 如何从Airtable数据库中提取图像?
当我试图编译我的代码时,我得到了错误: 我遵循一个教程,唯一的区别是Airtable中每个列/字段的名称。我的项目应该是有效的,但它不是。我忘了申报什么东西了吗?有没有更简单的方法从Airtable获取图像Reactjs 如何从Airtable数据库中提取图像?,reactjs,airtable,Reactjs,Airtable,当我试图编译我的代码时,我得到了错误: 我遵循一个教程,唯一的区别是Airtable中每个列/字段的名称。我的项目应该是有效的,但它不是。我忘了申报什么东西了吗?有没有更简单的方法从Airtable获取图像 import React,{Component}来自'React'; 导入{容器、行、列、卡、卡片、CardMg、CardText、CardBody、, 来自“reactstrap”的CardTitle、CardSubtitle、Button}; 导入“/main.css”; 类应用程序扩
import React,{Component}来自'React';
导入{容器、行、列、卡、卡片、CardMg、CardText、CardBody、,
来自“reactstrap”的CardTitle、CardSubtitle、Button};
导入“/main.css”;
类应用程序扩展组件{
建造师(道具){
超级(道具);
此.state={
技能:[],
};
}
componentDidMount(){
取('https://api.airtable.com/v0/appXy4JgrvUicfB5F/Resources?api_key=keyE0exOkvaAnJeS0')
.然后((resp)=>resp.json())
。然后(数据=>{
控制台日志(数据);
this.setState({skills:data.records});
}).catch(错误=>{
//错误对于许多对象,您正在使用的Airtable API中没有Picture
属性,并且在尝试访问Picture[0]
时失败,因为Picture未定义
如果没有所有对象的图像,简单的方法是在渲染之前先检查是否有图片
:
{Picture&&}
我花了大约两个小时在这上面,但没有取得任何进展。显然,我还需要回去学习更多关于React的知识。非常感谢您的帮助。我真的非常感谢!
import React, { Component } from 'react';
import { Container, Row, Col, Card, CardImg, CardText, CardBody,
CardTitle, CardSubtitle, Button } from 'reactstrap';
import './main.css';
class App extends Component {
constructor(props) {
super(props);
this.state = {
skills: [],
};
}
componentDidMount() {
fetch('https://api.airtable.com/v0/appXy4JgrvUicfB5F/Resources?api_key=keyE0exOkvaAnJeS0')
.then((resp) => resp.json())
.then(data => {
console.log(data);
this.setState({ skills: data.records });
}).catch(err => {
// Error The Airtable API that you are using does not have a Picture
property in for lots of objects and they are failing when trying to access Picture[0]
because Picture is undefined
.
If you do not have images for all objects, the easy way would be check if there is a Picture
first before rendering:
{Picture && <img className="card-img-left" src={Picture[0].url} />}