小编CJN*_*tts的帖子

计算反应中的数量和价格总和

我是React的新用户,我正在尝试设计的应用程序遇到问题.基本上我想要一个我可以让用户更新数量的产品列表,每个数量的总数将显示在产品下面,整个包的总数将显示在底部.如果有人可以帮助我,我将非常感激.我的代码包含在`下面

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";

class App extends Component {


  render() {
    /* This is the Counter Part of the App used to denote the quantity of items*/
     class Counter extends React.Component {
      constructor(props) {
        super(props);

        this.state = {
          count: 0
        };
      }

      onUpdate = (val) => {
        this.setState({
          count: val
        });
      };

      render() {

        return (
          <div>
            <CounterChild onUpdate={this.onUpdate} />
            <br />
            <OtherChild passedVal={this.state.count} />
          </div>
        )
      }
    }
    /*Counter …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

使用 React 将提交的表单值保存在 JSON 文件中

我正在尝试在 React 中创建一个表单,它将在提交时使用表单中的值更新 JSON 文件。(最终结果是,每次提交表单时,这将在 JSON 文件中创建一个数据数组,然后可用于在应用程序的其他地方填充提交结果的“列表”)

表单本身工作正常,但每次我按提交时都会收到错误消息:“TypeError: fs.writeFile is not a function”

import React, { Component } from "react";
import { Form, Button } from 'semantic-ui-react';
import jsonfile from'jsonfile';

var file = 'data.json'

var obj = {name: 'JP'}


export default class App extends Component {
  constructor(props) {
    super(props)

    this.state = {
      name: "",
      email: ""
    }

    this.handleChange = this.handleChange.bind(this);
    this.sendDataSomewhere = this.sendDataSomewhere.bind(this);
}


handleChange = (e, {name, value}) => {
  this.setState({[name]: value})
}

sendDataSomewhere = function jsonfile(file){
jsonfile.writeFile(file, obj, …
Run Code Online (Sandbox Code Playgroud)

javascript forms json reactjs

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

标签 统计

javascript ×2

reactjs ×2

forms ×1

json ×1