vue 事件基础

v-on 

缩写:@

v-on:click="handle($event)"     $event可以获取到该dom的基础信息           https://cn.vuejs.org/v2/api/#v-on

 

其他的

HTML 事件属性写法与之类似

http://www.w3school.com.cn/tags/html_ref_eventattributes.asp

onafterprintscript文档打印之后运行的脚本。
onbeforeprintscript文档打印之前运行的脚本。
onbeforeunloadscript文档卸载之前运行的脚本。
onerrorscript在错误发生时运行的脚本。
onhaschangescript当文档已改变时运行的脚本。
onloadscript页面结束加载之后触发。
onmessagescript在消息被触发时运行的脚本。
onofflinescript当文档离线时运行的脚本。
ononlinescript当文档上线时运行的脚本。
onpagehidescript当窗口隐藏时运行的脚本。
onpageshowscript当窗口成为可见时运行的脚本。
onpopstatescript当窗口历史记录改变时运行的脚本。
onredoscript当文档执行撤销(redo)时运行的脚本。
onresizescript当浏览器窗口被调整大小时触发。
onstoragescript在 Web Storage 区域更新后运行的脚本。
onundoscript在文档执行 undo 时运行的脚本。
onunloadscript一旦页面已下载时触发(或者浏览器窗口已被关闭)。

例如:onload 换成vue的写法就是 v-on:load="handle($event)"      或    @load="handle($event)" 

v-on:  就相当于  onload 前缀的on用法,其他的用法类似

其他的我没试过不知道是不是这样的额,猜想应该是这样的额

@load的用法

 <div class="imgAll">
         <!--屏幕宽度: {{screenWidth}}-->
          <ul>
            <li v-for="(value,key) in imageUrls" class="imgBox" >
              <div class="box">
                <img :src="value" @load="drawImage_box($event)" class="imsg">
              </div>
              <i class="delImg" v-on:click="delImg(key)"> X </i>
            </li>
            <li >
              <div class="z_file">
                <input type="file" name="file" class="inputstyle"  @change="PreviewImage"/>
              </div>
            </li>
          </ul>
        </div>
//获取缩略图盒子宽高后再执行缩放
      drawImage_box(e){
          var width_img= $(".imgBox").width();
          var height_img= $(".imgBox").height();
          // console.log(width_img + "," + height_img);
          this.DrawImage( e.target,width_img, height_img);
        },
      //图片缩放居中核心功能
      DrawImage(ImgID,width_s, height_s) {
        var image = new Image();
        let imgInfo = ImgID;
        if (imgInfo) {
          let src = ImgID.src;
          image.src = src;
          if (image.width > 0 && image.height > 0) {
            if (image.width / image.height <= width_s / height_s) {
              ImgID.width = width_s;
              var height = (image.height * width_s) / image.width;
              ImgID.height = height;
              ImgID.style.marginTop = -(height - height_s) / 2 + "px";
            } else {
              ImgID.height = height_s;
              var width = (image.width * height_s) / image.height;
              ImgID.width = width;
              ImgID.style.marginLeft = -(width - width_s) / 2 + "px";
            }
          }
        }
      },

 

转载于:https://www.cnblogs.com/itchenfirst/p/9987279.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值