小编cra*_*eer的帖子

如何在反应中将 onClick 事件放在字体真棒图标上?

我正在尝试在 fontawesome 图标上设置 onClick 事件,但是当我这样做时它不起作用。

 <i class="fab fa-accessible-icon" onClick={this.removeItems}></i>
Run Code Online (Sandbox Code Playgroud)

它仅在我将 onClick 放在 p 标签或 h 标签上时才有效。

 <h1 onClick={this.removeItems}><i class="fab fa-accessible-icon"></i></h1>
Run Code Online (Sandbox Code Playgroud)

无法在图标本身上设置事件?以第二种方式执行此操作会导致我出现样式错误。

编辑:我确实将课程更改为 className,我的错。但它仍然无法正常工作,目前我在图标周围使用它并在跨度上使用 onClick 绕过它。

font-awesome reactjs

10
推荐指数
1
解决办法
2万
查看次数

如何从 React.js 发送带有图像的 multipart/form-data?

我正在尝试使用 React 表单将表单发送到我的 Express.js 后端。它仅发送文本,但不发送文件。通过表单发送文件时是否需要建立FormData?这是我在 App.js 上的表单

    class App extends Component {
     constructor(props) {
      super(props);
       this.state={
        inputTopValue:'',
        inputBottomValue:'',
        inputImageValue: '',
            }
    this.handleTopChange = this.handleTopChange.bind(this);
    this.handleBottomChange = this.handleBottomChange.bind(this);
    this.handleImageChange = this.handleImageChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
             }

    handleTopChange(event) {
       this.setState({inputTopValue: event.target.value});
               }

   handleBottomChange(event) {
    this.setState({inputBottomValue: event.target.value});
             }

   handleImageChange(event) {
    this.setState({inputImageValue: event.target.value
              }

   handleSubmit(event) {
    event.preventDefault();
    fetch('api/learning', {
        method: 'POST',
        headers: {
          'Content-Type': 'multipart/form-data',
          'Accept': 'application/json'
        },
         body: JSON.stringify({
             topstuff: event.target.topstuff.value,
             bottomstuff: event.target.bottomstuff.value,
             pic1: event.target.myimage.value

         })
    })
  }

   render() {
       return (
         <div className="App"> …
Run Code Online (Sandbox Code Playgroud)

reactjs

9
推荐指数
1
解决办法
3万
查看次数

在资产管道错误中出现资产不存在后,无法将我的Rails应用程序部署到heroku

我的应用程序可以在我的本地主机上正常运行,但是现在正在尝试将其部署到heroku上,并显示:

We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
Run Code Online (Sandbox Code Playgroud)

日志文件:

2017-07-28T06:32:05.150511+00:00 app[web.1]: F, [2017-07-28T06:32:05.150434 #4] FATAL -- : [333bb637-4f97-41fa-8b90-60452df2b4fd]   
2017-07-28T06:32:05.150586+00:00 app[web.1]: F, [2017-07-28T06:32:05.150519 #4] FATAL -- : [333bb637-4f97-41fa-8b90-60452df2b4fd] ActionView::Template::Error (The asset "landingherodrink.jpeg" is not present in the asset pipeline.):
2017-07-28T06:32:05.150803+00:00 app[web.1]: F, [2017-07-28T06:32:05.150736 #4] FATAL -- : [333bb637-4f97-41fa-8b90-60452df2b4fd]     10:                 </div>
2017-07-28T06:32:05.150806+00:00 app[web.1]: [333bb637-4f97-41fa-8b90-60452df2b4fd]     11:         </div>
2017-07-28T06:32:05.150806+00:00 app[web.1]: [333bb637-4f97-41fa-8b90-60452df2b4fd]     12:         <div id="landingherodrink">
2017-07-28T06:32:05.150808+00:00 app[web.1]: [333bb637-4f97-41fa-8b90-60452df2b4fd]     13:                 <%= image_tag("landingherodrink.jpeg") %>
2017-07-28T06:32:05.150808+00:00 app[web.1]: …
Run Code Online (Sandbox Code Playgroud)

deployment ruby-on-rails heroku

7
推荐指数
2
解决办法
2166
查看次数

从 React 获取 API 向我发送错误的 URL

学习 React.js 和 Node.js,并使用后端的 Express API 和前端的 React.js 制作一个简单的 CRUD 应用程序。我的 React.js 的 App.js 看起来像这样。

    `import React, { Component } from 'react';
     import './App.css';
     import Rentals from './components/Rentals';
     import Idpage from './components/Idpage';

     import {
      BrowserRouter as Router,
      Route,
      Link
     } from 'react-router-dom';

   class App extends Component {

   render() {
    return (
    <div className="mainappdiv">
     <Router>
          <main>
            <Route exact path="/" component={Home} />
            <Route exact path="/rentals" component={Rentals} />
            <Route path="/rentals/:propertyid" component={Idpage} />
          </main>             
        </div>           
    </Router>
  </div>
      );
     }}

 export default App;
Run Code Online (Sandbox Code Playgroud)

我正在制作一个应用程序,当您访问 /rentals …

api node.js reactjs fetch-api

2
推荐指数
1
解决办法
4523
查看次数

单击按钮时如何渲染元素:ReactJS

我在您单击按钮时尝试渲染一个段落.

这是我的代码.

import React, { Component } from 'react';

class App extends Component {
  constructor() {
    super();
    this.createText = this.createText.bind(this);
  }


  createText() {
    return(
      <p>hello friend</p>
    )
  }


  render() {
    return (
      <div className="App">
        <button onClick={this.createText}>Click</button>
      </div>
    );
  }
}

export default App;
Run Code Online (Sandbox Code Playgroud)

在这里,我试图在单击按钮时呈现"你好朋友".但是没有用.

javascript reactjs

2
推荐指数
1
解决办法
1426
查看次数

psql:严重:尝试访问psql时由于用户错误而导致密码身份验证失败

我正在使用Windows 10并为此安装了Psql(9.6.4)。安装时,它要求我输入超级用户“ postgres”的密码,我输入的密码为“ asdfasdf”。因此,安装后,我使用来检查版本,psql --version并显示了当前版本,因此我猜它已正确安装。但是,当我进入git bash并输入时psql,它会要求输入密码,因此我输入了我输入的密码“ asdfasdf”,但它说psql: FATAL: password authentication failed for user "Bobby" 我确定密码正确并输入了几次,所以我也不知道为什么会说用户“ Bobby”的身份验证失败。Bobby只是计算机的用户名。键入后出现提示时,我输入的密码是否错误psql

database postgresql

1
推荐指数
1
解决办法
2925
查看次数

如何使用where条件从Spring Boot中的表中获取所有值?

我正在学习Spring Boot,基本上想做一个这样的查询,返回年龄为 5 的所有行。

SELECT * FROM pets WHERE age = 5;

JPA借助 Spring Boot,使用和可以轻松获取所有宠物或具有唯一 id 的宠物,Hibernate而且我可以简单地做到这一点。

PetsController.java

//for all pets
@GetMapping
    public List<Pet> getAllPets() {
        return petService.getAllPets();
    }

//for getting one pet with unique id
@GetMapping("{id}")
    public ResponseEntity<Pet> getPetById(@PathVariable("id") int petId) {
        ResponseEntity<Pet> matchingPet = new ResponseEntity<Pet>(petService.getPetById(petId), HttpStatus.OK);
        return matchingPet;
    }
Run Code Online (Sandbox Code Playgroud)

PetService.java

public interface PetService {
    List<Pet> getAllPets();
    Pet getPetById(int petId);
}
Run Code Online (Sandbox Code Playgroud)

PetServiceImpl.java

@Service
public class PetServiceImpl implements PetService {

    private PetRepository petrepository; …
Run Code Online (Sandbox Code Playgroud)

java sql spring spring-boot

0
推荐指数
1
解决办法
3万
查看次数