前端学习问题与经验总结

Property assignment expected 

google后得知问题出在jsx的return后面写的statement是用 () 的,而不是 {} 。包括element也是一样的,用()

A class member cannot have the 'const' keyword

字面意思。可以用readonly代替。(具体用法本人还没看

class xxx extends xx {
    render(){ ... }
}

有些奇怪这个render后面跟一个括号再跟curly braces的操作。是同理function render() { ... }吗?

HTML form的attribute:action onSubmit onClick

The action is an attribute that specifies where to send the form-data when a form is submitted. (aka what is the 2nd page that is supposed to receive the form-data once this form is submitted)

The onsubmit attribute is used to specify which JS code to run.

注意,React里面要写onSubmit而不是onsubmit

关于React的component

什么是component:a button, a form, a dialog, a screen...

详细请参看React.Component – React

The only method you must define in a React.Component subclass is called render()

These methods are called in the following order when an instance of a component is being created and inserted into the DOM:

Updating

An update can be caused by changes to props or state. These methods are called in the following order when a component is being re-rendered:

Unmounting

This method is called when a component is being removed from the DOM:

Error Handling

These methods are called when there is an error during rendering, in a lifecycle method, or in the constructor of any child component.

super(props) 

When implementing the constructor for a React.Component subclass, you should call super(props) before any other statement. Otherwise, this.props will be undefined in the constructor 

 constructor(props)

Typically, in React constructors are only used for two purposes:

注意constructor里面不要写this.setState(), 可以写this.state = { ... } 

而在其他地方要写setState。

js-onchange //同样 在react里面camel-cased

The onchange event occurs when the value of an element has been changed.

参考onchange Event 

useState hook

好像是一个新特性代替setState 还没看

 Your render method should have a return statement

字面意思

class名必须大写

此处省略debug时的无数句脏话

setState需key与value一一对应

setState的异步

用btn还是href还是router?

btn可以配合onClick,改变props

router,实现页面的变换

如何实现button在中间

把button用div框起来

    <div class="col text-center">
      <button class="btn btn-default">Centered button</button>
    </div>

实现按下按钮调用modal

首先,bootstrap docs中,modal的定义如下:

  • Modals are positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead.

即modal一定会盖过其他所有东西。

我本来尝试onClick={Modal()},并在Modal里return 想展示的modal。事实证明这是本人瞎搞。

解决的办法是把想展示的modal放在button的整一个的return的后面,并且用isOpen来控制modal的展示与否。

关于onClick={}里面到底是什么

理论上说是一个function。但是不加()?

关于onChange

下面一段话解释了event.target.value是什么意思。

The value of the prop is the handleChange function; It is an event handler. The event that the handler receives as a parameter is an object that contains a target field. This target is the DOM element that the event handler is bound to (ie, the text input field). By accessing this field, we can determine what the target's value is changed to.

关于如何点击按钮,执行函数,再redirect

不知道为什么react-route的navigate一直没有用。最后用<Link to="url" onClick={xxx}>实现了,,

axios向后端发请求,后端redirect,前端这边没用

大概就是人家axios根本就没打算让你redirect。后改为

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值