【问题标题】:is any one can help me with this issue on tinder cards有人能帮我解决火种卡上的这个问题吗
【发布时间】:2021-08-18 16:16:33
【问题描述】:

我正在学习如何构建 tinder 克隆,但是当我尝试使用 url 传递一些图像时它不起作用,我尝试更改 url 但图像发生而不显示图像。 这是我的代码。 火种卡:

import React, { useState } from 'react';
import TinderCard from 'react-tinder-card';
import './TinderCards.css';

function TinderCards(){
const [people, setpeople] = useState([{
    name: 'jonathan pascal',
    url: "https://static1.purepeople.com/articles/4/86/40/4/@/687935-steve-jobs-a-san-francisco-le-9- 
624x600-3.jpg",
},
{
    name:'bahavu atosha',
    url: "",
}

]); 
return(
    <div>
        <h1>Muhimu cards</h1>
        {people.map(person=> (
            <TinderCard
             className="swipe"
             key={person.name}
             preventSwipe={['up', 'down']}
             >
                <div 
                style={{ backgroundImage: 'url(${person.url})' }} 
                className="card">
                    <h3>{person.name}</h3>
                </div>
            </TinderCard>
        ))}

    </div>
  )
 }
  export default TinderCards;

【问题讨论】:

  • 你在style={{ backgroundImage: 'url(${person.url})' }} 使用反引号(模板文字)吗?看来您正在使用单引号。尝试使用模板文字或反引号。

标签: reactjs tinder


【解决方案1】:

我主要通过修复与模板文字相关的语法问题来解决您的问题。

import React, { useState } from "react";
import TinderCard from "react-tinder-card";
import "./TinderCards.css";

function TinderCards() {
  const [people, setpeople] = useState([
    {
      name: "jonathan pascal",
      url: "https://static1.purepeople.com/articles/4/86/40/4/@/687935-steve-jobs-a-san-francisco-le-9-624x600-3.jpg", // Line breaking issue exist here before
    },
    {
      name: "bahavu atosha",
      url: "",
    },
  ]);
  return (
    <div>
      <h1>Muhimu cards</h1>
      {people.map((person) => (
        <TinderCard
          className="swipe"
          key={person.name}
          preventSwipe={["up", "down"]}
        >
          <div
            style={{
              backgroundImage: `url(${person.url})` /* Add backticks here */,
            }}
            className="card"
          >
            <h3>{person.name}</h3>
          </div>
        </TinderCard>
      ))}
    </div>
  );
}
export default TinderCards;

如果您需要进一步的支持,请告诉我。

【讨论】:

  • 我是 react js 的初学者,所以我真的不知道反引号,我是从教程中学习 js,所以当你说要添加反引号时,我不知道怎么做要继续,请帮助我!!!
  • 当然。您可以在此处详细了解模板文字。 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
猜你喜欢
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
相关资源
最近更新 更多