Open navydong opened 5 years ago
tips: import、require在浏览器为什么不能使用
webpack只是一个打包模块的机制,只是把依赖的模块转化成可以代表这些包的静态文件。并不是什么commonjs或者amd之类的模块化规范。 webpack就是识别你的 入口文件。识别你的模块依赖,来打包你的代码。至于你的代码使用的是commonjs还是amd或者es6的import。webpack都会对其进行分析。来获取代码的依赖。webpack做的就是分析代码。转换代码,编译代码,输出代码。 webpack本身是一个node的模块,所以webpack.config.js是以commonjs形式书写的(node中的模块化是commonjs规范的) webpack中每个模块有一个唯一的id,是从0开始递增的。整个打包后的bundle.js是一个匿名函数自执行。参数则为一个数组。数组的每一项都为个function。function的内容则为每个模块的内容,并按照require的顺序排列。
使用reduce高阶函数
const arr = [ 1,2,3,4,5,6,6,4,3,2 ]
function removeDulp (init, current){
if( init.indexOf(current)>-1 ){
return init
}
init.push( current )
return init
}
const res = arr.reduce( removeDulp, [] )
使用css3 Mutil-column特性
<div class="masonry">
<div class="item">
<div class="item__content">
</div>
</div>
<div class="item">
<div class="item__content">
</div>
</div>
<!-- more items -->
</div
.masonry {
width:100%;
column-gap:10px;
column-count: 5;
margin: 0 auto;
}
.item {
box-sizing: border-box;
-webkit-column-break-inside: avoid; /* Chrome, Safari, Opera */
page-break-inside: avoid; /* Firefox */
break-inside: avoid; /* IE 10+ */
padding: 10px;
counter-increment: item-counter;
/* 下面这两行代码是为了兼容火狐浏览器的因为内容太长而出现断层的问题。*/
height:100%;
overflow: auto;
}
/* 利用媒体查询,增加响应式布局 */
.masonry {
column-count: 1; // one column on mobile
}
@media (min-width: 400px) {
.masonry {
column-count: 2; // two columns on larger phones
}
}
@media (min-width: 1200px) {
.masonry {
column-count: 3; // three columns on...you get it
}
}
// 正常正则验证字符串 reg.test(txt)
// 函数封装后
function check(reg, txt) {
return reg.test(txt)
}
check(/\d+/g, 'test') //false
check(/[a-z]+/g, 'test') //true
// Currying后
function curryingCheck(reg) {
return function(txt) {
return reg.test(txt)
}
}
var hasNumber = curryingCheck(/\d+/g)
var hasLetter = curryingCheck(/[a-z]+/g)
hasNumber('test1') // true
hasNumber('testtest') // false
hasLetter('21212') // false
一面:
1.前端登录的逻辑是什么?
登录的前后端交互流程、token过期问题
2.水平垂直居中