diff --git "a/2019/Commit Message\350\247\204\350\214\203.html" "b/2019/Commit Message\350\247\204\350\214\203.html" index 394504981..c77feab8d 100644 --- "a/2019/Commit Message\350\247\204\350\214\203.html" +++ "b/2019/Commit Message\350\247\204\350\214\203.html" @@ -1149,7 +1149,7 @@
display:inline-block 什么时候会显示间隙? 移除空格、使用margin负值、使用font-size:0、letter-spacing、word-spacing
ul标签内外边距问题ul标签在IE6\IE7中,有个默认的外边距,但是在IE8以上及其他浏览器中有个默认的内边距。 +解决方法:统一设置ul的内外边距为0
+IE6下图片的下方有空隙 +解决方法:给img设置display:block;
+IE6下两个float之间会有个3px的bug +解决办法:给右边的元素也设置float:left;
+IE6下没有min-width的概念,其默认的width就是min-width
+IE6下在使用margin:0 auto;无法使其居中 +解决办法:为其父容器设置text-align:center;
+被点击过后的超链接不再具有hover和active属性 +解决办法:按lvha的顺序书写css样式,
+本文标题:浏览器兼容问题总结
文章作者:陈宇(cosyer)
发布时间:2019年09月01日 - 01:09
-最后更新:2020年09月05日 - 21:09
+最后更新:2020年09月08日 - 19:09
@@ -966,7 +997,7 @@1 | const withUser = WrappedComponent => { |
withUser
函数就是一个高阶组件,它返回了一个新的组件,这个组件具有了它提供的获取用户信息的功能。
但是这两种模式会增加代码的层级关系,而hooks简洁多了,没有多余的层级嵌套,把各种想要的功能写成一个一个可复用的自定义hook,当你的组件想用什么功能时,直接在组件里调用这个hook即可。
+1 | // withGithubProfile |
引入高阶组件,使用其profile
+1
2
3
4
5
6
7
8
9
10
11
12
13
14
15class GithubProfileHoc extends React.Component<IProps, IStates> {
render() {
const { profile } = this.props
return (
<div className="profile">
<img src={profile.avatar_url} alt="avatar" width="200px" />
<div>name: {profile.name}</div>
<div>followers: {profile.followers}</div>
<div>following: {profile.following}</div>
</div>
)
}
}
export default WithGithubProfile(GithubProfileHoc)
生命周期钩子函数里的逻辑太乱了吧! 我们通常希望一个函数只做一件事情,但我们的生命周期钩子函数里通常同时做了很多事情。比如我们需要在componentDidMount中发起ajax请求获取数据,绑定一些事件监听等等。同时,有时候我们还需要在componentDidUpdate做一遍同样的事情。当项目变复杂后,这一块的代码也变得不那么直观。
class真的太让人困惑了! @@ -603,14 +611,6 @@
1 | // withGithubProfile |
引入高阶组件,使用其profile
-1
2
3
4
5
6
7
8
9
10
11
12
13
14
15class GithubProfileHoc extends React.Component<IProps, IStates> {
render() {
const { profile } = this.props
return (
<div className="profile">
<img src={profile.avatar_url} alt="avatar" width="200px" />
<div>name: {profile.name}</div>
<div>followers: {profile.followers}</div>
<div>following: {profile.following}</div>
</div>
)
}
}
export default WithGithubProfile(GithubProfileHoc)
1 | class Example extends React.Component { |
1 | import { useState } from 'react'; |
是不是简单多了!可以看到,Example变成了一个函数,但这个函数却有自己的状态(count),同时它还可以更新自己的状态(setCount)。
@@ -670,11 +670,11 @@1 | function FriendListItem(props) { |
比如还有
-1 | // useProfile |
1 | // useProfile |
使用 useProfile
Hooks:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23const UseProfilePage = () => {
const { profile, loading, isError } = useProfile()
return (
<React.Fragment>
{isError ? (
<div>Network Error...</div>
) : (
<div className="profile">
{loading ? (
<div>loading profile...</div>
) : (
<React.Fragment>
<img src={profile.avatar_url} alt="avatar" width="200px" />
<div>name: {profile.name}</div>
<div>company: {profile.company}</div>
<div>bio: {profile.bio}</div>
</React.Fragment>
)}
</div>
)}
</React.Fragment>
)
}
1 | const useInput = (initialValue:string) => { |
1 | const useInputDemo = () => { |
1 | const useInputDemo = () => { |
useContext
是为了在 function 组件中使用类组件的 context API,使用方法很简单,首先创建一个 context:
1
2const local = '🇨🇳'
const ThemeContext = React.createContext(local)useContext hook
使用 context:
@@ -690,7 +690,7 @@
返回当前 state 以及配套的 dispatch 方法。首先看下 useReducer
处理简单的 state:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18function UseReducerDemo() {
const [count, dispatch] = useReducer(state => {
return state + 1
}, 0)
return (
<div>
<p>count: {count}</p>
<button
onClick={() => {
dispatch()
}}
>
add
</button>
</div>
)
}useState
一样,都达到了计数的效果。 该例子中,useReducer
初始化了 count 值为 0,传入的 reducer 很简单,当接收到一个 dispatch 时,将 count 的值增加 1。
1 | const CountApp = () => { |
1 | const CountApp = () => { |
原因在于 function 组件的更新机制,当引入 hooks 以后,function 组件也拥有了 state 的功能,当我们 setState 时,UI 会重新渲染,但在这个过程中function 组件中,state 以及 props 都是静态值,不存在引用,或者也可以理解为 state 和 props 是一个 capture value,每次渲染的 state 和 props 都是独立的。
在这个例子中,由于 useEffect 传入的依赖为 [],即该副作用只会在 UI 第一次渲染结束后执行一次。而在这次 render 中,count 的值为 0, frozen 值为 false,所以第二次执行 increase 时,frozen 值依然为 false, setCount 返回的 prevCount 为 1 ,然后增加 1,这也就是为什么最后 render 的结果为 2,而不是 1。
对于 state 有相互依赖的情况,我们可以用 useReducer
来处理:
@@ -766,7 +766,7 @@
本文标题:30分钟精通React Hooks
文章作者:陈宇(cosyer)
发布时间:2020年05月12日 - 11:05
-最后更新:2020年07月15日 - 22:07
+最后更新:2020年09月08日 - 19:09
原始链接:http://mydearest.cn/2020/30%E5%88%86%E9%92%9F%E7%B2%BE%E9%80%9AReact%20Hooks.html
@@ -1115,7 +1115,7 @@面试遇到了问题:<p>中能不能插入<div>? 插入<div>会如何?
先直接实践下:
我们可以看到,
分成了两段, 并且div外字段并不在
内。把div变成行内块级元素也不行。
++我们可以看到,
把分成了两段, 并且div外字段并不在
内。把div变成行内块级元素也不行。
+
解答: 可以在HTML标准(https://www.w3.org/TR/html401/struct/text.html#h-9.3.1)中看到,
@@ -576,7 +578,7 @@over!
-文章作者:陈宇(cosyer)
发布时间:2020年09月02日 - 11:09
-最后更新:2020年09月05日 - 20:09
+最后更新:2020年09月08日 - 19:09
@@ -927,7 +929,7 @@本文标题:vue面试题记录
文章作者:陈宇(cosyer)
发布时间:2020年04月23日 - 00:04
-最后更新:2020年08月31日 - 22:08
+最后更新:2020年09月08日 - 19:09
原始链接:http://mydearest.cn/2020/vueInterview.html
@@ -1621,7 +1621,7 @@1 | "script": { |
++总结起来node有以下几个特点:简单强大,轻量可扩展.简单体现在node使用的是javascript,json来进行编码,人人都会;强大体现在非阻塞IO,可以适应分块传输数据,较慢的网络环境,尤其擅长 +高并发访问;轻量体现在node本身既是代码,又是服务器,前后端使用统一语言;可扩展体现在可以轻松应对多实例,多服务器架构,同时有海量的第三方应用组件。
+
基于事件驱动和无阻塞适合高并发的场景,统一语言
nodejs 其实并不是真正的单线程架构,因为 nodejs 还有I/O线程存在(网络I/O、磁盘I/O),这些I/O线程是由更底层的 libuv 处理,这部分线程对于开发者来 -说是透明的。 JavaScript 代码永远运行在V8上,是单线程的。
+说是透明的。 JavaScript 代码永远运行在V8上,是单线程的。异步通过一次次循环事件队列来实现的。文章作者:陈宇(cosyer)
发布时间:2020年06月21日 - 23:06
-最后更新:2020年08月31日 - 01:08
+最后更新:2020年09月08日 - 19:09
@@ -1006,7 +1025,7 @@通过fork,原理是子程序用process.on来监听父程序的消息,用 process.send给子程序发消息,父程序里用child.on,child.send进行交互,来实现父进程和子 +
通过fork,原理是子程序用process.on来监听父程序的消息,用 process.send给父程序发消息,父程序里用child.on,child.send进行交互,来实现父进程和子 进程互相发送消息。
++child-process和process的stdin,stdout,stderror是一样的吗?概念都是一样的,输入,输出,错误,都是流.区别是在父程序眼里,子程序的stdout是输入流,stdin是输出流
+
我们通过 use 注册中间件,中间件函数有两个参数第一个是上下文,第二个是 next,在中间件函数执行过程中,若遇到 next() ,那么就会进入到下一个中间件中执 行,下一个中间执行完成后,在返回上一个中间件执行 next() 后面的方法,这便是中间件的执行逻辑。
流在 nodejs 用的很广泛,但对于大部分开发者来说,更多的是使用流,比如说 HTTP 中的 request respond ,标准输入输出,文件读取 @@ -661,7 +664,7 @@
文章作者:陈宇(cosyer)
发布时间:2020年07月02日 - 00:07
-最后更新:2020年08月31日 - 01:08
+最后更新:2020年09月08日 - 19:09
@@ -1010,7 +1013,7 @@1 | function fn() { |
解析:(分治法) +
解析:(分治法) 将一个列表分割为左右两块,然后再将字列表再进行分割为左右两块,如何反复,知道子元素长度为1时,结束!
1 | function qSort(arr) { |
1 | function shuffle(arr) { |
[2,7,11,88,34],9 => [0,1]
1 | function twoSum(arr, target) { |
1 | function(arr, target) { |
1 | function(arr, target) { |
巴什博奕嘛保证剩最后6个给对面取,先取者可必胜,第一次取4个,剩126个,对面随便取,取的时候保证一直剩余6的倍数,最后一定出现剩6个苹果的情况。
+1 | function fetchWithLimit(urls, max, callback) { |
文章作者:陈宇(cosyer)
发布时间:2020年04月23日 - 01:04
-最后更新:2020年08月31日 - 20:08
+最后更新:2020年09月08日 - 19:09
原始链接:http://mydearest.cn/2020/%E7%AE%97%E6%B3%95%E9%A2%98%E7%BB%83%E4%B9%A0.html
@@ -1002,7 +1003,7 @@