# 1. Set获取值

a = new Set()
a.add('xxx')


a.values().next().value // 'xxx'

# 2. 将Map字符串化

function mapToObj(strMap){
  let obj= Object.create(null);
  for (let[k,v] of strMap) {
    obj[k] = v;
  }
  return obj;
}

/**
 * map转换为json
*/
function _mapToJson(map) {
return JSON.stringify(mapToObj(map), null, 4);
}

# 3. vant组件升级后,van-list有时无法滚动

这时可在#app,或者match-list-wrap等元素加上

.match-list-wrap {
  height: 100%;
  overflow-y: scroll;
}

主要是list的外层元素必须有一个overflow-yauto或者scroll

# 4. 带scope的eslint plugin在extends配置

假如插件名为 eslint-plugin-pmd,则配置如下:

extends: ['@tencent/eslint-config-light', 'plugin:@tencent/pmd/recommended'],

可参考:https://www.jianshu.com/p/6254093f846c

# 5. JS中可以存储多少位的数字

由于 JavaScript 采用 IEEE 754 标准,数值存储为64位双精度浮点格式(8Byte),数值精度最多可以达到 53 个二进制位(1 个隐藏位与 52 个有效位)。如果数值的精度超过这个限度,第54位及后面的位就会被丢弃,这种情况下,Number.isInteger可能会误判。

Number.isInteger(3.0000000000000002) // true
2**53+1 === 2**53 // true

# 6. 小于n的最大的2的N次方

Math.pow(2, Math.ceil(Math.log2( n )))

# 7. split切割多个空格

js 里的split函数,切割以空格(多个空格)作为分隔符的字符串

在使用split函数切割一个以空格为分隔符的字符串时,发现切出的长度和预期的长度不一致!!

let str = “hellow world!//注意hellow与world之前有两个空格
console.log(str.trim().split(" “))
console.log(str.trim().split(" ").length)

结果为 [“hellow”,“ ”,“world!”]

而我们希望的结果是 hellow 和 world,长度为2

此时,应该用正则表达式来进行切割

let str = “hellow world!//注意hellow与world之前有两个空格
console.log(str.trim().split(/\s+/))
console.log(str.trim().split(/\s+/).length)

结果为【“hellow”,“world!" 】

# 8. stylelint

# 8.1. 忽略 stylelint

如果是第三方库的css,直接在文件顶部加上 /* stylelint-disable */

如果是对某一段忽略,可以:

/* stylelint-disable */
body {
  text-size-adjust: none !important;
}

/* stylelint-enable */

# 8.2. 对某个文件强制执行stylelint

npx stylelint public/css/style_m.css --fix

# 9. vue-cli中css的厂商后缀会自动加

如果能把如下的css

.page-header-wrap {
  display: flex;
  flex-direction: column;
}

编译成:

.page-header-wrap  {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
}

就没问题

# 10. 写入文件的安全问题

安全问题,文件操作谨防输入..,代码需要判断

比如 fs.unlinkSync(filePath)fs.createReadStream(file.filepath)

# 11. 机器人总结

可以监听数据变化再发送,也可定时拉取数据发送,也可以监听远程数据、执行某种操作、发送通知

# 12. git tag

git tag v1.0.0...v1.1.0 查看两次tag之前的差异提交

git tag v1.0.0... 查看v1.0.0至今的提交,或者git log release-20220622-v1.4.2...HEAD

# 13. k8s

pod包含多个容器,node可代表实体机

# 14. mongodb中将时间戳转为Date类型

上面的date的值需要是mongo中的Date类型,所以上面才用

"$add":[new Date(0),"$timestamp"] ,这是为了把 $timestamp 的值转为Date类型

# 15. 多个动态参数如何高效拼接

function getExtraStr() {
  const { envVersion = '', version = '', appId = '' } = wx?.getAccountInfoSync?.()?.miniProgram || {};
  const { SDKVersion = '', platform = '' } = __wxConfig as any;

  const info = { envVersion, version, appId, SDKVersion, platform };

  return Object.keys(info).map((key) => {
    const value = info[key];
    return `${key}_${value}`;
  })
    .join('__');
}

# 16. Vue中的slot传递

父组件传递slot到子孙组件:

<ModuleHeaderMp>
  <template #middle>
    <div
      class="head-box"
    >
      消息中心
      <div class="head-title-icon">
        <div
          class="iconfont icon-eliminate"
          @click.stop="onClearAll()"
        />
      </div>
    </div>
  </template>
</ModuleHeaderMp>

子组件ModuleHeaderMp

<UiHeaderMp>
  <template #middle>
      <slot name="middle" />
  </template>
  <template #right>
      <slot name="right" />
  </template>
</UiHeaderMp>

孙组件UiHeaderMp

<template>
  <div class="middle">
    <slot name="middle" />
  </div>
  <div class="right">
    <slot name="right" />
  </div>
</template>
3 > 2 > 1

# 17. React 如何实现computed的呢

render函数中之间用个函数,比如之前是:

data={treeNode.toArray() as any}

加上computed

const showTreeNode = searchTree(treeNode.toArray(), search);

return <NodeTree
  data={showTreeNode as any}
/>