静修-个人博客


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索

100-js按位取反

发表于 2019-08-31 | 分类于 前端-02-js基础复习

按位取反~

基本概念:

这是js中的一元操作符:按位取反。

计算规则为:

1
~x = -(x+1);

即:~-1 = 0、~1 = -2。

就来看看~1的计算步骤:

  • 将1(这里叫:原码)转二进制 = 00000001

  • 按位取反 = 11111110

  • 发现符号位(即最高位)为1(表示负数),将除符号位之外的其他数字取反 = 10000001

  • 末位加1取其补码 = 10000010

转换回十进制 = -2

indexOf 神操作

~取反的用法是,是因为-1的取反操作等于0,而其他数的取反操作不等于0。所以用indexOf操作符可以用~操作来判断某个字符串里是否有某个字符。

1
2
3
4
5
6
var str = '123456'
if(~str.indexOf(0)){
console.log('因为取反之后不为零,说明indexOf的结果不等于-1,所以表示str字符串里包含了对应字符')
} else {
console.log('说明取反之后为零,说明indexOf的结果等于-1,所以表示str字符串里不包含了对应字符')
}

参考文章
参考文章

10-构造函数加不加props

发表于 2019-08-31 | 分类于 前端-05-react

加与不加props的区别究竟在哪里呢?

以下来自stackoverflow的解释:

What’s the difference between “super()” and “super(props)” in React when using es6 classes?

不加props

1
2
3
4
constructor(props) {
super();
console.log(this.props) //undefined
}

加props

1
2
3
4
constructor(props) {
super(props);
console.log(this.props) //props will get logged.
}

37-css3文本两端对齐

发表于 2019-08-31 | 分类于 前端-01-切图CSS
1
2
<div class="box">你好好了</div>
<div class="box">你好</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
.box {
width: 100px;
border: 1px solid #000;
padding: 10px;
text-align: justify;
&:after {
content: "";
width: 100%;
display: inline-block;
overflow: hidden;
height: 0;
}
}

image

09-angular-commit规范

发表于 2019-08-31 | 分类于 前端-10-git
  • feat:新功能(feature)
  • fix:修补bug
  • docs:文档(documentation)
  • style: 格式(不影响代码运行的变动)
  • refactor:重构(即不是新增功能,也不是修改bug的代码变动)
  • test:增加测试
  • chore:构建过程或辅助工具的变动

99-js解绑监听事件

发表于 2019-08-31 | 分类于 前端-02-js基础复习

addEventListener()和removeEventListener()用来绑定事件和解绑事件

它们都接受3个参数addEventListener(eventName,function,true)

第三个参数为true表示在捕获阶段调用事件处理程序,false表示在冒泡阶段调用事件处理程序

例如:

1
2
3
4
window.addEventListener('resize',function(event){
event.preventDefault();
console.log('调整浏览器窗口大小时触发resize事件')
},false)

当移除事件时用removeEventListener()

1
2
3
4
window.removeEventListener('resize',function(event){
event.preventDefault();
console.log('解绑resize事件')
},false)

但是发现并没有解绑成功!!!

因为解绑和绑定时的函数名要相同,也就意味着通过addEventListener绑定的匿名函数是不能解绑的

正确的绑定和解绑示例:

1
2
3
4
5
6
function resizeWindow(event){
event.preventDefault();
console.log('调整浏览器窗口大小时触发resize事件')
}
window.addEventListener('resize', resizeWindow, false);
window.removeEventListener('resize', resizeWindow, false);

这样就ok了

版权声明:本文为CSDN博主「xmy_wh」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xmy_wh/article/details/84634410

14-个人前端常用工具软件

发表于 2019-08-31 | 分类于 前端-00-基础

windows个人常用的软件

1.工具软件

  1. git :版本管理工具

  2. tortoisegit :git图形管理工具

  3. tortoisesvn :svn版本管理工具

  4. photoshop :前端切图必备

  5. animate cc :需要动画的时候用

  6. 有道云笔记 :有markdown模式,笔记写代码很方便

  7. postman :调试接口

  8. fiddler :抓包工具

  9. Koala :一款编译scss,less的软件,官网下载建议迅雷下载。

  10. ditto: 剪切板管理神器

  11. Snipaste: 截图神器

  12. GifCam: 录制GIF神器

  13. synergy: 键鼠共用神器参考

  14. chrome浏览器 :

    • 常用插件:

      • AngularJS Batarang
      • cross-request 3.0 : YApi 跨域请求
      • EZ Zoom
      • Google 翻译
      • JetBrains IDE Support
      • Lighthouse
      • Octotree:逛github项目目录用的
      • React Developer Tools
      • Redux DevTools
      • Screencastify
      • Tampermonkey
      • Vue.js devtools
      • Wappalyzer
      • WhatFont
      • Xdebug helper
      • 扩展程序二维码(QR码)生成器(QR Code Generator)
      • 掘金
  15. 火狐浏览器

  16. xshell
  17. FileZilla
  18. nvm-windows
  19. nodejs

    • 常用全局包(看个人需要安装)
      • @vue/cli
      • @vue/cli-init (vue-cli2.0)
      • autoprefixer
      • babel-cli
      • browser-sync
      • cnpm
      • egg-init
      • eslint
      • gulp
      • hexo-cli
      • http-server
      • jshint
      • prettier
      • rimraf
      • vsce
      • yarn
      • yx-easy-gulp
      • typescript
      • create-react-app
      • create-react-native-app
      • dva-cli
      • exp
      • react-native-cli
      • wepy-cli
      • windows-build-tools

2.前端idea

  1. sublime text3 :由于转vscode了,sublime只作简单的文本编辑。

    • 插件列表:

      • Package Control 安装在 新版sublime text3 不用 ctrl+~ 输入一段长长的命令行了,可以在命令行下输入pack选择第一项就行了。
      • 中文汉化插件:ChineseLocalization
      • IMESupport
      • a file icon,boxy theme 主题插件
  2. vscode :目前写代码的主要idea

    • 常用插件:

      • Autoprefixer
      • Bracket Pair Colorizer 2
      • Chinese (Simplified) Language Pack for Visual Studio Code
      • Dart
      • Document This
      • eggjs
      • Element UI Snippets
      • ESLint
      • File Header Comment
      • Flutter
      • Git History
      • GitLens — Git supercharged
      • Insert Date String
      • IntelliSense for CSS class names in HTML
      • jQuery Code Snippets
      • minapp
      • minify
      • mpvue snippets
      • npm Intellisense
      • NPM-Scripts
      • Open HTML in Default Browser
      • Path Intellisense
      • Prettier - Code formatter
      • px2rem+
      • Quokka.js
      • Settings Sync
      • stylelint
      • Sublime Text Keymap and Settings Importer
      • Turbo Console Log
      • Vetur
      • VS Code CSS Comments
      • vscode-element-helper
      • Vue 2 Snippets
      • Vue VSCode Snippets
    • 已停用或弃用插件:

      • Auto Rename Tag
      • Live Share
      • Angular 1.x snippets
      • NPM-Scripts
      • PHP Debug
      • PHP IntelliSense

97-Object.create

发表于 2019-08-31 | 分类于 前端-02-js基础复习

object.create() 是使用指定的原型proto对象及其属性propertiesObject去创建一个新的对象。

1
2
3
4
5
6
7
8
9
10
Object.myCreate = function (obj, properties)  {
var F = function () {}
F.prototype = obj
if (properties) {
Object.defineProperties(F, properties)
}
return new F()
}

Object.myCreate({}, {a: {value: 1}}) // {a: 1}

37-vscode配置stylelint

发表于 2019-06-29 | 分类于 前端-01-切图CSS

时隔两月,vscode prettier的设置已经更改,所以重新记录下

1 vscode安装插件prettier和stylelint

1.1 下载地址

  • stylelint
  • Prettier Formatter for Visual Studio Code

1.2 配置

在 /.vscode/settings.json 增加配置,这样做是为了同步项目中的配置,当然,你可以在全局设置中设置

附带vscode eslint配置如下 ^_^

settings.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// eslint 设置
"eslint.validate": [
"html",
{
"language": "vue",
"autoFix": true
},
{
"language": "javascript",
"autoFix": true
},
{
"language": "javascriptreact",
"autoFix": true
}
],
"eslint.autoFixOnSave": true,
/* prettier配置遵循eslint规则 */
"prettier.jsxSingleQuote": true,
"prettier.semi": false,

// stylelint配置
"stylelint.enable": true,
"css.validate": false,
"less.validate": false,
"scss.validate": false,
"[scss]": {
"editor.formatOnSave": true
},

2 项目安装相应依赖包

1
2
3
yarn add --dev stylelint-config-prettier stylelint-prettier

yarn add prettier --dev --exact

然后,在根目录加上.stylelintrc.js

1
2
3
4
5
6
7
8
9
10
11
12
13
module.exports = {
processors: [],
plugins: [],
extends: ["stylelint-prettier/recommended"],
rules: {
// 取消某些规则如下:
"unit-case": null,
"rule-empty-line-before": null,
"comment-empty-line-before": null,
"declaration-block-trailing-semicolon": null,
"selector-type-no-unknown": null
}
};

最后,加上忽略文件.prettierignore和.prettierignore

1
2
node_modules
dist

至此,设置完毕!~

3 taro项目单位PX大写自动格式化成小写问题

在 Taro 中尺寸单位建议使用 px、 百分比 %,Taro 默认会对所有单位进行转换。当前忽略单个属性的最简单的方法,就是 px 单位使用大写字母Px or PX。

由于我们之前已经设置prettier插件自动格式化[scss]文件,导致写PX会被自动格式化成小写px

如何避免这个问题,只要在上面写/* prettier-ignore */即可避免自动格式化成小写字母

1
2
/* prettier-ignore */
height: 44PX;

参考文章
stylelint插件
文档-prettier与Linters集成
掘金-css代码规范工具stylelint
掘金-VScode下搭配ESLint、TSLint、stylelint的代码检查配方
掘金-vscode + prettier 专治代码洁癖(一)

36-vscode配置csscomb

发表于 2019-06-29 | 分类于 前端-01-切图CSS

setting.json

1
2
3
// css 自动格式化,vscode 需要安装 csscomb 插件
"csscomb.formatOnSave": true,
"csscomb.preset": "./.vscode/csscomb.json"

csscomb.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
{
"exclude": [".git/**", "node_modules/**", "bower_components/**"],
"sort-order": [
[
"position",
"top",
"right",
"bottom",
"left",
"z-index",
"display",
"visibility",
"float",
"clear",
"overflow",
"-ms-overflow-x",
"-ms-overflow-y",
"overflow-x",
"overflow-y",
"-webkit-overflow-scrolling",
"clip",
"-webkit-align-content",
"-ms-flex-line-pack",
"align-content",
"-webkit-box-align",
"-moz-box-align",
"-webkit-align-items",
"align-items",
"-ms-flex-align",
"-webkit-align-self",
"-ms-flex-item-align",
"-ms-grid-row-align",
"align-self",
"-webkit-box-flex",
"-webkit-flex",
"-moz-box-flex",
"-ms-flex",
"flex",
"-webkit-flex-flow",
"-ms-flex-flow",
"flex-flow",
"-webkit-flex-basis",
"-ms-flex-preferred-size",
"flex-basis",
"-webkit-box-orient",
"-webkit-box-direction",
"-webkit-flex-direction",
"-moz-box-orient",
"-moz-box-direction",
"-ms-flex-direction",
"flex-direction",
"-webkit-flex-grow",
"-ms-flex-positive",
"flex-grow",
"-webkit-flex-shrink",
"-ms-flex-negative",
"flex-shrink",
"-webkit-flex-wrap",
"-ms-flex-wrap",
"flex-wrap",
"-webkit-box-pack",
"-moz-box-pack",
"-ms-flex-pack",
"-webkit-justify-content",
"justify-content",
"-webkit-box-ordinal-group",
"-webkit-order",
"-moz-box-ordinal-group",
"-ms-flex-order",
"order",
"-webkit-box-sizing",
"-moz-box-sizing",
"box-sizing",
"margin",
"margin-top",
"margin-right",
"margin-bottom",
"margin-left",
"padding",
"padding-top",
"padding-right",
"padding-bottom",
"padding-left",
"min-width",
"min-height",
"max-width",
"max-height",
"width",
"height",
"outline",
"outline-width",
"outline-style",
"outline-color",
"outline-offset",
"border",
"border-spacing",
"border-collapse",
"border-width",
"border-style",
"border-color",
"border-top",
"border-top-width",
"border-top-style",
"border-top-color",
"border-right",
"border-right-width",
"border-right-style",
"border-right-color",
"border-bottom",
"border-bottom-width",
"border-bottom-style",
"border-bottom-color",
"border-left",
"border-left-width",
"border-left-style",
"border-left-color",
"-webkit-border-radius",
"-moz-border-radius",
"border-radius",
"-webkit-border-top-left-radius",
"-moz-border-radius-topleft",
"border-top-left-radius",
"-webkit-border-top-right-radius",
"-moz-border-radius-topright",
"border-top-right-radius",
"-webkit-border-bottom-right-radius",
"-moz-border-radius-bottomright",
"border-bottom-right-radius",
"-webkit-border-bottom-left-radius",
"-moz-border-radius-bottomleft",
"border-bottom-left-radius",
"-webkit-border-image",
"-moz-border-image",
"-o-border-image",
"border-image",
"-webkit-border-image-source",
"-moz-border-image-source",
"-o-border-image-source",
"border-image-source",
"-webkit-border-image-slice",
"-moz-border-image-slice",
"-o-border-image-slice",
"border-image-slice",
"-webkit-border-image-width",
"-moz-border-image-width",
"-o-border-image-width",
"border-image-width",
"-webkit-border-image-outset",
"-moz-border-image-outset",
"-o-border-image-outset",
"border-image-outset",
"-webkit-border-image-repeat",
"-moz-border-image-repeat",
"-o-border-image-repeat",
"border-image-repeat",
"-webkit-border-top-image",
"-moz-border-top-image",
"-o-border-top-image",
"border-top-image",
"-webkit-border-right-image",
"-moz-border-right-image",
"-o-border-right-image",
"border-right-image",
"-webkit-border-bottom-image",
"-moz-border-bottom-image",
"-o-border-bottom-image",
"border-bottom-image",
"-webkit-border-left-image",
"-moz-border-left-image",
"-o-border-left-image",
"border-left-image",
"-webkit-border-corner-image",
"-moz-border-corner-image",
"-o-border-corner-image",
"border-corner-image",
"-webkit-border-top-left-image",
"-moz-border-top-left-image",
"-o-border-top-left-image",
"border-top-left-image",
"-webkit-border-top-right-image",
"-moz-border-top-right-image",
"-o-border-top-right-image",
"border-top-right-image",
"-webkit-border-bottom-right-image",
"-moz-border-bottom-right-image",
"-o-border-bottom-right-image",
"border-bottom-right-image",
"-webkit-border-bottom-left-image",
"-moz-border-bottom-left-image",
"-o-border-bottom-left-image",
"border-bottom-left-image",
"background",
"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader",
"background-color",
"background-image",
"background-attachment",
"background-position",
"-ms-background-position-x",
"-ms-background-position-y",
"background-position-x",
"background-position-y",
"-webkit-background-clip",
"-moz-background-clip",
"background-clip",
"background-origin",
"-webkit-background-size",
"-moz-background-size",
"-o-background-size",
"background-size",
"background-repeat",
"box-decoration-break",
"-webkit-box-shadow",
"-moz-box-shadow",
"box-shadow",
"color",
"table-layout",
"caption-side",
"empty-cells",
"list-style",
"list-style-position",
"list-style-type",
"list-style-image",
"quotes",
"content",
"counter-increment",
"counter-reset",
"-ms-writing-mode",
"vertical-align",
"text-align",
"-webkit-text-align-last",
"-moz-text-align-last",
"-ms-text-align-last",
"text-align-last",
"text-decoration",
"text-emphasis",
"text-emphasis-position",
"text-emphasis-style",
"text-emphasis-color",
"text-indent",
"-ms-text-justify",
"text-justify",
"text-outline",
"text-transform",
"text-wrap",
"-ms-text-overflow",
"text-overflow",
"text-overflow-ellipsis",
"text-overflow-mode",
"text-shadow",
"white-space",
"word-spacing",
"-ms-word-wrap",
"word-wrap",
"-ms-word-break",
"word-break",
"-moz-tab-size",
"-o-tab-size",
"tab-size",
"-webkit-hyphens",
"-moz-hyphens",
"hyphens",
"letter-spacing",
"font",
"font-weight",
"font-style",
"font-variant",
"font-size-adjust",
"font-stretch",
"font-size",
"font-family",
"src",
"line-height",
"opacity",
"-ms-filter:\\'progid:DXImageTransform.Microsoft.Alpha",
"filter:progid:DXImageTransform.Microsoft.Alpha(Opacity",
"-ms-interpolation-mode",
"-webkit-filter",
"-ms-filter",
"filter",
"resize",
"cursor",
"nav-index",
"nav-up",
"nav-right",
"nav-down",
"nav-left",
"-webkit-transition",
"-moz-transition",
"-ms-transition",
"-o-transition",
"transition",
"-webkit-transition-delay",
"-moz-transition-delay",
"-ms-transition-delay",
"-o-transition-delay",
"transition-delay",
"-webkit-transition-timing-function",
"-moz-transition-timing-function",
"-ms-transition-timing-function",
"-o-transition-timing-function",
"transition-timing-function",
"-webkit-transition-duration",
"-moz-transition-duration",
"-ms-transition-duration",
"-o-transition-duration",
"transition-duration",
"-webkit-transition-property",
"-moz-transition-property",
"-ms-transition-property",
"-o-transition-property",
"transition-property",
"-webkit-transform",
"-moz-transform",
"-ms-transform",
"-o-transform",
"transform",
"-webkit-transform-origin",
"-moz-transform-origin",
"-ms-transform-origin",
"-o-transform-origin",
"transform-origin",
"-webkit-animation",
"-moz-animation",
"-ms-animation",
"-o-animation",
"animation",
"-webkit-animation-name",
"-moz-animation-name",
"-ms-animation-name",
"-o-animation-name",
"animation-name",
"-webkit-animation-duration",
"-moz-animation-duration",
"-ms-animation-duration",
"-o-animation-duration",
"animation-duration",
"-webkit-animation-play-state",
"-moz-animation-play-state",
"-ms-animation-play-state",
"-o-animation-play-state",
"animation-play-state",
"-webkit-animation-timing-function",
"-moz-animation-timing-function",
"-ms-animation-timing-function",
"-o-animation-timing-function",
"animation-timing-function",
"-webkit-animation-delay",
"-moz-animation-delay",
"-ms-animation-delay",
"-o-animation-delay",
"animation-delay",
"-webkit-animation-iteration-count",
"-moz-animation-iteration-count",
"-ms-animation-iteration-count",
"-o-animation-iteration-count",
"animation-iteration-count",
"-webkit-animation-direction",
"-moz-animation-direction",
"-ms-animation-direction",
"-o-animation-direction",
"animation-direction",
"pointer-events",
"unicode-bidi",
"direction",
"-webkit-columns",
"-moz-columns",
"columns",
"-webkit-column-span",
"-moz-column-span",
"column-span",
"-webkit-column-width",
"-moz-column-width",
"column-width",
"-webkit-column-count",
"-moz-column-count",
"column-count",
"-webkit-column-fill",
"-moz-column-fill",
"column-fill",
"-webkit-column-gap",
"-moz-column-gap",
"column-gap",
"-webkit-column-rule",
"-moz-column-rule",
"column-rule",
"-webkit-column-rule-width",
"-moz-column-rule-width",
"column-rule-width",
"-webkit-column-rule-style",
"-moz-column-rule-style",
"column-rule-style",
"-webkit-column-rule-color",
"-moz-column-rule-color",
"column-rule-color",
"break-before",
"break-inside",
"break-after",
"page-break-before",
"page-break-inside",
"page-break-after",
"orphans",
"widows",
"-ms-zoom",
"zoom",
"max-zoom",
"min-zoom",
"user-zoom",
"orientation"
]
],

"always-semicolon": true,
"block-indent": " ",
"color-case": "lower",
"color-shorthand": false,
"eof-newline": true,
"leading-zero": false,
"quotes": "single",
"space-after-colon": " ",
"space-after-combinator": " ",
"space-after-opening-brace": "\n ",
"space-after-selector-delimiter": "\n",
"space-before-closing-brace": "\n",
"space-before-colon": "",
"space-before-combinator": " ",
"space-before-opening-brace": " ",
"space-before-selector-delimiter": "",
"strip-spaces": true,
"unitless-zero": true,
"vendor-prefix-align": true
}

96-切换npm源

发表于 2019-06-29 | 分类于 前端-02-js基础复习

全局配置切换到淘宝源

1
npm config set registry https://registry.npm.taobao.org

全局配置切换到官方源

1
npm config set registry https://registry.npmjs.org

查看当前地址

1
npm config get registry
123…33
静修

静修

322 日志
19 分类
19 标签
© 2019 静修
本站访客数:
由 Hexo 强力驱动
主题 - NexT.Pisces