Open yanyue404 opened 2 years ago
v-bind=item
字符串出现次数最多字符获取
先递增后递减数组极大值获取
二分查找
// 例: [0,1,4,7,5] => 7 [1,6,5,3,2] => 6
实现粘性定位-快滑出屏幕时吸顶或吸底
axios 源码
// MDN 示例:在文档可见时开始播放音乐曲目,在文档不再可见时暂停音乐 document.addEventListener("visibilitychange", function () { if (document.visibilityState === "visible") { backgroundMusic.play(); } else { backgroundMusic.pause(); } });
// 省略若干代码 export default { props: { show: { type: Boolean, default: true, }, /** * 设置在mask上面滑动能不能滚动页面, 默认不能滚动页面 */ noScrollingPage: { type: Boolean, default: true, }, }, computed: { maskStyle() { return { position: "fixed", backgroundColor: `rgba(0,0,0, ${this.opacity})`, height: "100%", width: "100%", top: 0, left: 0, zIndex: getZIndex(), }; }, }, watch: { noScrollingPage(val) { val ? this.disableScrollPage() : this.enableScrollpage(); }, show(val) { val && this.noScrollingPage ? this.disableScrollPage() : this.enableScrollpage(); }, }, mounted() { this.$el.addEventListener("touchmove", this.scrollHander, true); this.show && this.noScrollingPage && this.disableScrollPage(); }, destroyed() { this.enableScrollpage(); this.$el.removeEventListener("touchmove", this.scrollHander); }, methods: { disableScrollPage() { document.documentElement.style.overflow = "hidden"; }, enableScrollpage() { document.documentElement.style.overflow = ""; }, scrollHander(e) { const getNeed = (el) => { if (el == this.$el || !el || !el.parentElement) { return false; } if (el.className.indexOf("mask-content-needscroll") >= 0) { return true; } return getNeed(el.parentElement); }; if (this.noScrollingPage && this.show && !getNeed(e.target)) { e.preventDefault(); } }, }, };
常见问题
v-bind=item
https://cn.vuejs.org/v2/api/#v-bind代码评审高频问题
扩展
字符串出现次数最多字符获取
先递增后递减数组极大值获取
二分查找
实现粘性定位-快滑出屏幕时吸顶或吸底
axios 源码
补充