2019年7月

两种方案清除定时器,开发者经常使用方案1,建议使用方案2方案1首先我在data函数里面进行定义定时器名称:data() { return { timer: null // 定时器名称 } }, 然后这样使用定时器:this.timer = (() => { // 某些操作 }, 1000) 最后在beforeDestroy()生命周期内清除定时器:beforeDestroy() { clearInte- 阅读剩余部分 -

vue-piczoom 基于vue2.x的电商图片放大镜插件,修复了图片放大的一些bug,看懂的就看看,看不懂的就算了,太忙没时间写笔记备注了,可以自己用对比工具去看下修改了哪些<template> <div class="magnifier-box" :class="vertical?'vertical':''" :ref="id" @mousemove="mousemove" @mouseover="mouseover" @mouseleave- 阅读剩余部分 -

因为加载图片是异步的,在图片的相关数据没有加载完之后,宽高都是默认为0,所以我们要给imgDom增加个onload方法。let imgDom = new Image(); imgDom.src = this.bigUrl?this.bigUrl:this.url; imgDom.onload = () => { // 打印数据 console.log('width:' + imgDom.width + ', height:' + imgDom.height); }