最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何传递数据,例如用户名,并将其放在他们创建的帖子中

运维笔记admin19浏览0评论

如何传递数据,例如用户名,并将其放在他们创建的帖子中

如何传递数据,例如用户名,并将其放在他们创建的帖子中

[ 所以我正在为活动创建应用程序,由于某种原因,当用户创建活动时,偶数信息会显示,但用户信息(例如其姓名和照片)不会显示,请帮助我现在有这个问题将近一个星期。

这是componentDidMount函数

  async componentDidMount() {
    const { data } = await getCategories();
    const categories = [{ _id: "", name: "All Categories" }, ...data];

    const { data: events } = await getEvents();
    this.setState({ events, categories });

    console.log(events);
  }

这是国家

class Events extends Component {
  state = {
    events: [],
    user: getUser(),
    users: getUsers(),
    showDetails: false,
    shownEventID: 0,
    showUserProfile: false,
    shownUserID: 0,
    searchQuery: ""
  };

这是显示用户名和照片的事件文件

<Link>
                    <img
                      className="profilePic mr-2"
                      src={"/images/" + event.hostPicture}
                      alt=""
                      onClick={() => this.handleShowUserProfile(event.userId)}
                    />
                  </Link>

                  <Link style={{ textDecoration: "none", color: "black" }}>
                    <h4
                      onClick={() => this.handleShowUserProfile(event.userId)}
                      className="host-name"
                    >
                      {getUser(event.userId).name}
                    </h4>
                  </Link>

这是getUser函数所在的userService文件

import http from "./httpService";

const apiEndPoint = "http://localhost:3100/api/users";

export function register(user) {
  return http.post(apiEndPoint, {
    email: user.email,
    password: user.password,
    name: user.name
  });
}

export function getUsers() {
  return http.get(apiEndPoint);
}

export async function getUser(userId) {
  const result = await http.get(apiEndPoint + "/" + userId);
  return result.data;
}

这是事件所在的eventService文件

import http from "./httpService";

const apiEndPoint = "http://localhost:3100/api/events";

export function getEvents() {
  return http.get(apiEndPoint);
}

export function getEvent(eventId) {
  return http.get(apiEndPoint + "/" + eventId);
} 

export function saveEvent(event) {
    if(event._id){
        const body = {...event}
        delete body._id
        return http.put(apiEndPoint + '/' + event._id, body)
    } 
    return http.post(apiEndPoint, event);
}

export function deleteEvent(eventId) {
  return http.delete(apiEndPoint + "/" + eventId);
}
回答如下:

首先,在class元素中使用<div>有一些错误。请使用className代替class

发布评论

评论列表(0)

  1. 暂无评论