最近偷懒了,好久没更新
想要留下的代码
1.图片引用的onerror的属性
<img src="images/logo.png" οnerrοr="javascript:this.src='images/logoError.png';">
图片images/logo.png加载出错则加载images/logoError.png
2.获取当天零点的时间戳
new Date(new Date().toLocaleDateString()).getTime()
3.ztree文件夹的图标不展示了可参考ztree error
4.隐藏滚动条(产品觉得滚动条太丑,要把它隐藏)
.scrollbar {
scrollbar-width: none;
-ms-overflow-style: none;
overflow-y: auto;
overflow-x: hidden; // 这里不能和overflow-y合并写,ie下会有问题
}
.scrollbar::-webkit-scrollbar {
display: none;
}
5.网站使用svg格式的图片在本地测试正常,放到服务器上后不能显示,解决方法是修改图片的类型,svg有点特殊,可参考svg mime
6.svg自适应
#home {
max-width: 100%;
max-height: 100%;
}
这样的话图片就会自动按宽或高自适应,可能不会按比例来,图片会变形
7.前端图片压缩 有库可引用image-conversion
import * as imageConversion from 'image-conversion'
async compressImg(file, size, orientation) {
let result
await imageConversion
.compressAccurately(file, {
size,
orientation,
file: 'image/jpeg'
})
.then(res => {
result = res
})
return result
},
8.获取图片旋转角度使用 exif-js
import * as EXIF from 'exif-js'
await EXIF.getData(this.file, async function() {
that.Orientation = EXIF.getTag(this, 'Orientation')
})
9.H5页面日志打印
在html里引入
<!--H5调试-->
<script src="https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js"></script>
<script>
// H5调试
var vConsole = new VConsole()
</script>
遇到的坑
1.ElementUI国际化时遇到的坑
element 版本从1升到了2,使用原理的i8n逻辑发现没效果,后面才发现有个地方更改了,看到区别了吗? vm.t => t
Vue.use(Element, {
i18n: (key, value) => i18n.vm._t(key, value)
})
Vue.use(Element, {
i18n: (key, value) => i18n.t(key, value)
})
2.Css 在移动端的特殊样式 在做会h5页面的时候,有个按钮在移动端点击会出现蓝色背景,但是在pc上则不会,后来查到在移动端有个测试样式可控制-webkit-tap-highlight-color: 参考移动端css
3.移动端图片上传有些手机会对图片进行旋转 经测试安卓里,小米手机会旋转,苹果手机部分机型会旋转,也就是图片的Orientation参数不为1,但是某些版本的ios手机Orientation不为1但是确实没有旋转的,这就有点坑了,参考该文章进行排查ios手机上传图片旋转
学习
1.科技爱好者周刊