
获得徽章 0
- // 获取字符串长度 中文字符占2
const getStrLength = (str: string): number => {
const len = str.length;
let reLen = 0;
for (let i = 0; i < len; i++) {
if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
reLen += 2;
} else {
reLen += 1;
}
}
return reLen;
};展开评论点赞 - webpack 打包 less 时启用 localIdentName 导致 keyframes 动画失效
加 :local 即可解决问题
.fadeIn :local {
animation: fadeIn 2.5s ease-out;
animation-iteration-count: infinite;
}
@keyframes fadeIn {
from {
opacity: 0.1;
}
to {
opacity: 1;
}
}展开评论点赞 - antd v4.0 引用 antd.less 报错,需要搭配 less v3.12.x 一起
ERROR in ./src/index.less (./node_modules/css-loader/dist/cjs.js??ref--4-1!./node_modules/less-loader/dist/cjs.js??ref--4-2!./src/routes/reoprt/index.less)
Module build failed (from ./node_modules/less-loader/dist/cjs.js):
/* stylelint-disable-next-line function-calc-no-invalid */
padding-right: calc(@drawer-header-close-padding - var(--scroll-bar));
...
解决办法,less 版本需要升级到最新的3.12.x后解决展开评论点赞 - rm -rf 引发的血案
> npm install
npm ERR! Cannot read property 'resolve' of undefined
不小心删了部分npm的文件,然后成功损坏了npm,好在重新安装后恢复了,rm -rf 还是要小心啊展开赞过评论2 - 在所有情况下,都取到顶层对象的两种方法(勉强可以使用)。
// 方法一
(typeof window !== 'undefined'
? window
: (typeof process === 'object' &&
typeof require === 'function' &&
typeof global === 'object')
? global
: this);
// 方法二
var getGlobal = function () {
if (typeof self !== 'undefined') { return self; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }
throw new Error('unable to locate global object');
};展开赞过评论1 - 将对象冻结,应该使用Object.freeze方法。const 只能保证这个指针是固定的
const foo = Object.freeze({});
// 常规模式时,下面一行不起作用;
// 严格模式时,该行会报错
foo.prop = 123;展开赞过评论1