1/移动端在对页面高度进行适配的时候,height:100vh,可以搭配js计算出的实时高度来通过css变量赋值。
const documentHeight=()=>{
const doc=document.documentElement
doc.style.setProperty('--doc-height',`${window.innerHeight}px`)
}
window.addEventListener('resize',documentHeight)
documentHeight():root{
--doc-height:100%
}
html,body{
padding:0,
marging:0,
height:100vh,
height:var(--doc-height)
}
2/reduce的几种用法
针对对象数组某个值的求和
let initialValue = 0
let sum= [{x: 1}, {x: 2}, {x: 3}].reduce(
(previousValue,currentValue)=>
previousValue + currentValue.x,initialValue
)
console.log(sum) // logs 6
数组的求和
let total = [ 0, 1, 2, 3 ]
.reduce(
(previousValue, currentValue )
=> previousValue +currentValue
, 0)
3/umi中的dva数据流
组件通过调用dispatch 就是action 来通过effects 去请求对应的服务端或者直接调用对应reducer来更改相应的model达到数据更新。
后台返回数据后 通过异步的yield关键词 获取,并通过 yield put 调用对应的reducer来更新对应的model,组件上也通过connect关键字来将对应的model挂载到当前组件的props上并且包括对应的dispatch.
dva是一种单项数据流,由页面的dispatch发起相应的action,来促使数据model更新,更新后的model又通过connect挂载到对应的组件上使页面更新。所有的数据都在model中统一注册管理,便于应用的管理和维护。