React API Reference - PullRequest
       14

React API Reference

0 голосов
/ 02 ноября 2018

enter image description here

«Список» - это API_Call из «Axios.get».

Я хочу проверить API "src" Пусто или нет.

Как я могу проверить это.

Ответы [ 4 ]

0 голосов
/ 02 ноября 2018

<Card key={result.id}
  hoverable
  style={{ width:240 }}
  cover={ () => {

    const cardImage = result.volumeInfo.imageLinks.thumbnail

    // If result.volumeInfo.imageLinks.thumbnail is defined, render
    // image with it, otherwise rendering some other fallback image
    return (cardImage ? 
      <img alt="example" src={ cardImage } /> :
      <img alt="example" src="/some-empty-image.jpg" />)
  }} >    

  <Meta title={result.volumeInfo.title} />
</Card>
0 голосов
/ 02 ноября 2018

Возможно, вы могли бы использовать условную логику, подобную этой, для визуализации либо изображения для result.volumeInfo.imageLinks.thumbnail, либо какого-либо другого запасного изображения, если result.volumeInfo.imageLinks.thumbnail не определено?

Итак, что-то вроде следующего:

<Card key={result.id}
  hoverable
  style={{ width:240 }}
  cover={ () => {

    const cardImage = result.volumeInfo.imageLinks.thumbnail

    // If result.volumeInfo.imageLinks.thumbnail is defined, render
    // image with it, otherwise rendering some other fallback image
    return (cardImage ? 
      <img alt="example" src={ cardImage } /> :
      <img alt="example" src="/some-empty-image.jpg" />)
  }} >    

  <Meta title={result.volumeInfo.title} />
</Card>
0 голосов
/ 02 ноября 2018

Это должно работать

src={result.volumeInfo.title == "" ? "empty-src" : result.volumeInfo.title }
0 голосов
/ 02 ноября 2018
Call a get API using axios and check response.
// Make a request for a list
 axios.get('URL path')
  .then(function (response) {
    console.log(response);
    //put ur condition code here if exits or not whatever u want
  })
  .catch(function (error) {
    console.log(error);
  });
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...