当前位置: 首页 > news >正文

24年7月-8月工作笔记整理(前端)

目录

  • 一、问题解决
  • 二、基础知识学习

一、问题解决

1.浏览器拦截跳转的解决方案

//先打开一个空白页let winHandler = window.open('', '_blank')//再重定向到想要跳转的链接winHandler.location.href = redirectUrl

2.文字大小跟随父级元素宽度适配缩放

//父元素加不换行和相对定位,子元素通过计算得出缩放的比例,以及偏移的量,最后实现缩放后居中
//html:<div  style='position: 'retactive', white-space: nowrap;'><div:style="{transform: `scale(${item.scale}) translateX(-${item.offsetX}%)`,position: 'absolute',left: '50%'}">{{ item.quotaSymbol }}</div></div>//js:
//文字自适应父级宽度缩放,返回缩放比例
//入参:文字内容,文字的信息,父元素宽度
export function scaleRatio(text, font, parentWidth) {//计算文字的宽度const canvas = document.createElement('canvas')const context = canvas.getContext('2d')context.font = fontconst { width } = context.measureText(text)return parentWidth / Math.max(width, parentWidth)
}

3.pc端实现滚动懒加载

//html:<div class="content" v-loading="noticeLoading" @scroll="watchScroll"><div v-if="noticeData && noticeData.length > 0"><divclass="content-card"v-for="(item, index) in noticeData":key="index"@click="toDetail(item.messageType, item.businessId)"><div class="notice-title"><div class="title-style">{{ item.title }}</div><divclass="more"style="font-weight: 400"v-if="item.messageType === '36'">详情 <i class="el-icon-arrow-right"></i></div></div><div class="notice-text">{{ item.content }}</div><div class="notice-text time">{{ item.sendTime }}</div></div><div class="dataDesc"><span v-if="dataLoading && !finished"><i class="el-icon-loading"></i>加载中...</span><span v-else>没有更多了</span></div></div><i-no-data v-if="noticeData.length === 0 && !noticeLoading">暂无消息提醒</i-no-data></div>//  js:
data(){
return{//消息通知//一次多少页pageSize: 10,//第几页pageNum: 1,//总共条数total: 0,//懒加载loadingdataLoading: false,//判断是否加载完成finished: true,switch: false, // 加锁,防止滚动时,判断条件重复调用
}
}//滚动方法watchScroll(e) {const scrollTop = e.target.scrollTop // listBox 滚动条向上卷曲出去的长度,随滚动变化const clientHeight = e.target.clientHeight // listBox 的视口可见高度,固定不变const scrollHeight = e.target.scrollHeight // listBox 的整体高度,随数据加载变化const saveHeight = 30 // 安全距离,距离底部XX时,触发加载const tempVal = scrollTop + clientHeight + saveHeight // 向上卷曲距离 + 视口可见高度 + 安全距离// 如果不加入 saveHeight 安全距离,在 scrollTop + clientHeight == scrollHeight 时,触发加载// 加入安全距离,相当于在 scrollTop + clientHeight >= scrollHeight - 30 时,触发加载,比前者更早触发if (tempVal >= scrollHeight) {if (!this.finished && !this.switch) {// 数据加载未结束 && 未加锁this.queryUserMessage()}this.switch = true // 加锁,防止重复触发}},//获取消息通知async queryUserMessage() {this.dataLoading = truetry {const { list, total } = await getMessage({farmId: this.farmId,pageSize: this.pageSize,pageNum: this.pageNum,orgId: this.orgId})this.loading = falseif (list && list.length > 0) {this.noticeData = this.noticeData.concat(list)this.total = totalif (list.length < this.pageSize ||this.noticeData.length >= this.total) {// 返回结果条数少于请求条数,认为已结束// 目前数据条数等于总条数,认为已结束this.finished = true} else {this.finished = falsethis.pageNum += 1 // 页码加1this.switch = false // 还可以继续加载,改变锁状态}}this.noticeLoading = false} catch (error) {this.noticeLoading = falseconsole.log('error===', error)}},

4.字体抗锯齿设置

//App.vue
#app {/* 字体抗锯齿,让字体看起来更清晰 */-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;
}

二、基础知识学习

1.vue3的watch

//监听ref:
watch(name, (currentValue, prevValue) => {console.log(currentValue, prevValue)
})
//监听reactive:(要使用箭头函数)
watch(() => nameObj.name, (newVal, oldVal) => {console.log(newVal, oldVal)
})
//监听多个 reactive :(且一个数组装现值,一个数组装旧值)
watch([() => nameObj.name, () => nameObj.englishName], ([curName, curEng], [preName, preEng]) => {console.log(curName, preName, '----', curEng, preEng)
})

2.vue3的组件间ref使用,父组件通过ref调用子组件的方法或数据需要子组件暴露出来

//父组件:
const cardRef = ref<InstanceType<typeof HomeOrderCard>>()
onMounted(() => {cardRef.value?.sayHello()
})
//子组件:
const sayHello = () => {console.log('hello')alert('are you ok?')
}
defineExpose({sayHello
})

3.History.pushState()方法用于在历史中添加一条记录。
window.history.pushState(state, title, url)
History.replaceState()方法用来修改 History 对象的当前记录,其他都与pushState()方法一模一样。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 惠中科技光伏清洗剂:科技创新引领绿色清洁新风尚
  • <数据集>车辆识别数据集<目标检测>
  • 详细阐述Android开发中常见的报错类型
  • .NetCore发布到IIS
  • MySQL高可用性实践指南
  • Efficient LoFTR论文阅读(特征匹配)
  • RabbitMQ练习(Routing)
  • graphviz安装仍报错 | 路径问题 | 已解决
  • 前端项目运行汇总
  • mysql优化升级
  • C++学习/复习补充记录 --- 图论(深搜,广搜)
  • uniapp使用tki-qrcode插件生成二维码,并且可以分享给微信好友
  • 千云物流 -低代码平台MySQL在linux安装
  • 深入理解计算机系统阅读笔记-第三章
  • 【NLP自然语言处理】文本处理的基本方法
  • gulp 教程
  • jquery ajax学习笔记
  • Linux编程学习笔记 | Linux多线程学习[2] - 线程的同步
  • mac修复ab及siege安装
  • magento 货币换算
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • node入门
  • python 学习笔记 - Queue Pipes,进程间通讯
  • sessionStorage和localStorage
  • Stream流与Lambda表达式(三) 静态工厂类Collectors
  • vue从创建到完整的饿了么(11)组件的使用(svg图标及watch的简单使用)
  • 半理解系列--Promise的进化史
  • 从0到1:PostCSS 插件开发最佳实践
  • 服务器从安装到部署全过程(二)
  • 聚类分析——Kmeans
  • 面试题:给你个id,去拿到name,多叉树遍历
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • 微信小程序:实现悬浮返回和分享按钮
  • 因为阿里,他们成了“杭漂”
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • 阿里云API、SDK和CLI应用实践方案
  • 仓管云——企业云erp功能有哪些?
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • (04)odoo视图操作
  • (1)安装hadoop之虚拟机准备(配置IP与主机名)
  • (55)MOS管专题--->(10)MOS管的封装
  • (C++20) consteval立即函数
  • (附源码)springboot人体健康检测微信小程序 毕业设计 012142
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (四)js前端开发中设计模式之工厂方法模式
  • (转)菜鸟学数据库(三)——存储过程
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .libPaths()设置包加载目录
  • .NET C# 使用 iText 生成PDF
  • .net core Swagger 过滤部分Api
  • .net 中viewstate的原理和使用
  • .NET/C# 编译期间能确定的相同字符串,在运行期间是相同的实例
  • .net6Api后台+uniapp导出Excel