1

我有以下代码实现

module.exports.post_get_follower = async (req, res) => {

Post.find({ 'email': res.locals.user.email })
    .then(posts => {
        res.json(posts);
    });
}

router.get('/post-user-follower', postController.post_get_follower);

我用以下实现来称呼它

fetch('http://localhost:8080/api/person/' + hiddenElement)
    .then(res => res.json())
    .then(pers => {
        pers.persons.forEach(person => {

            const mail = person.email;

            fetch('/post-user-follower')
              .then(res => res.json())
              .then(posts => {
              posts.reverse();
              posts.forEach(post => {

              const div = document.createElement('div');

              const header = document.createElement('h3');
              header.textContent = post.email;

              const text = document.createElement('p');
              text.textContent = post.text;

              const date = document.createElement('small');
              date.textContent = new Date(post.createdAt);
              
              const placeholder = document.createElement('p');
              placeholder.innerHTML = '<br>'; 

              div.appendChild(header);
              div.appendChild(text);
              div.appendChild(date);
              div.appendChild(placeholder);

              postsElement.appendChild(div);
              });
            });

        });
  });

如何在 module.exports 中定义一个参数并在我的第二个实现中像“ email:参数”(而不是res.locals.user.email)一样使用它module.exports,如何const mail在我的第二个实现中调用它?

4

0 回答 0