小编AFA*_*FAF的帖子

如何使用 CSS 绘制 pacman 形状?

我想用 CSS 制作一个像图像一样的椭圆,但我做不到。

我用figma制作了那个椭圆(蓝色的看起来像“pacman”),figma并没有告诉我如何做椭圆的css,只有位置,我需要知道如何绘制椭圆。

在此输入图像描述

另一个(有 3 层)我将使用它作为图像,因为我打赌它比第一个椭圆更难。

提前非常感谢!

css css-shapes

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

Reactjs 组件状态下的单元测试 Jest

你好 :) 我开始学习使用JEST 和 Enzyme 的单元测试

在我使用Reactjs 的色游戏”版本(已经完成)上,但是当我开始测试我的 Square 组件时,我什至无法测试我的颜色状态值和单击时的颜色状态(clickSquare 函数)...

我找不到很多关于它的资源,你能看到有什么问题吗,我该如何测试我的 Square 组件?

Square.js 组件:

import React, { Component } from 'react';



class Square extends Component {




constructor(props) {
    super(props);
    this.state = {
      color: undefined
    }
    this.clickSquare = this.clickSquare.bind(this);
  }

  componentDidMount() {
    if (this.props.color) {
      this.setState({
        color: this.props.color
      })
    }
  };

  componentWillReceiveProps(props) {
    //results in the parent component to send updated props,, 
    //whenever the propositions are updated in the parent, runs this
    //to …
Run Code Online (Sandbox Code Playgroud)

unit-testing reactjs jestjs enzyme

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

ReactJS - 如何从 MongoDB Date.now 更改日期格式

我正在使用 MongoDB 和 ReactJS。

所以我希望用户可以看到创建新项目的时间,但是 mongodb 显示此日期格式“2018-10-08 18:09:56.628”,而我只想显示“2018-10-08”。我能做什么?

我的项目架构:

let mongoose = require("mongoose");

let projectSchema = new mongoose.Schema({

  projectname: String,
  typeofproject: String,
  imageURL: String,
  dateMonthFrom: String,
  dateYearFrom: String,
  dateMonthTo: String,
  dateYearTo: String,
  tasks: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Tasks'
  }],
user: [{
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  }],
created: {
    type:Date,
    default: Date.now
    }
})

module.exports = mongoose.model('Project', projectSchema);
Run Code Online (Sandbox Code Playgroud)

我的反应代码:

[...]
  <header>
     <div>
        <h1>

{this.state.project.projectname} // "Title"
{this.state.project.created} // "2018-10-08 18:09:56.628"

        </h1>

     </div>
  </header>
[...]
Run Code Online (Sandbox Code Playgroud)

schema date mongodb reactjs

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

useState初始值不要直接使用该值

我有一个初始状态,我从不直接在代码中使用,只在另一个设置值状态中使用

仅举一个草稿示例:

interface PersonProps {}

const Person: React.FC<PersonProps> = () => {
  const [name, setName] = useState<string>("")
  const [todayYear, setTodayYear] = useState<string>("")
  const [birthYear, setBirthYear] = useState<string>("")
  const [age, setAge] = useState<string>("")

  const getPerson = async () => {
    try {
      const response = await getPersonRequest()
      const data = await response.data

      setName(data.name)
      setTodayYear(data.today_year)
      setBirthYear(data.future_year)
      setAge(data.todayYear - data.birthYear)
    } catch (error) {
      console.log(error)
    }
  }

  useEffect(() => {
    getPerson()
  })


  return (

    <h1>{name}</h1>
    <h2>{age}</h2>
  )

}
export default Person
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如您所见,我永远不会在 UI …

typescript reactjs react-hooks react-typescript

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

使用 Reactjs DatePicker 更新状态不起作用

我使用 datepicker 添加项目并且它可以工作,但是当我尝试使用 datepicker 编辑/更新这些项目时,它不起作用!给我很多错误,例如:

  • 失败丙类型:无效支柱selected型的string供给DatePicker,预期object

  • 组件正在更改要控制的文本类型的不受控制的输入。输入元素不应从不受控制切换到受控制(反之亦然)。决定在组件的生命周期内使用受控或非受控输入元素。

  • 失败的道具类型:无效的支柱selected型的string供给Calendar/Month/Week/Day,预计object

  • 未捕获的类型错误:无法读取未定义的属性“值”

并且输入为空,没有像预期的那样显示今天的日期,例如: 在此处输入图片说明

这是我的 EditProject 组件:

import React, { Component } from 'react';
import { NavLink } from 'react-router-dom';
import DatePicker from 'react-datepicker';
import moment from 'moment';

import './EditProject.css';
import 'react-datepicker/dist/react-datepicker.css';


class EditProject extends Component {
    constructor(props) {
        super(props);
        this.state = {
            project: {}
        }    
    }

    componentDidMount() {

        // console.log('PROPS ' + JSON.stringify(this.props));

        const { match: { params …
Run Code Online (Sandbox Code Playgroud)

javascript datepicker reactjs react-datepicker

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