首页 > 其他分享 >vue 监听事件addEventListener

vue 监听事件addEventListener

时间:2022-08-29 18:56:07浏览次数:45  
标签:vue methods handleEventListener 事件 addEventListener 监听

vue 添加监听事件addEventListener

// vue 添加监听事件,addEventListener第二个参数要绑在this上,即需要在methods中声明,否则销毁的时候会报错
// 在mounted中监听,在beforeDestroy中销毁,绑定的事件在methods中声明
mounted() {
    // 监听
    window.addEventListener('resize', this.handleEventListener)
  },
beforeDestroy() {
  // 销毁
  window.removeEventListener('resize', this.handleEventListener)
},
methods: {
  // 监听执行的事件
  handleEventListener() {
    
  },
}

标签:vue,methods,handleEventListener,事件,addEventListener,监听
From: https://www.cnblogs.com/jia-zq/p/16637014.html

相关文章

  • Vue封装的过渡与动画
    一.作用:在插入、更新或移除DOM元素时,在合适的时候给元素添加样式类名。二.图示: 三.写法:1.准备好样式元素进入的样式:v-enter:进入的起点v-enter......
  • vue3+vuex 的 mutations 的 使用
    <template><divclass="app">姓名:{{$store.state.nameVuex}}<button@click="btn">基本方法:修改名字</button><br/><button@click="btn1">传递值......
  • vue2+vuex 的 mutations 的 使用
    <template><divclass="app">姓名:{{$store.state.nameVuex}}<button@click="btn">基本方法:修改名字</button><br/><button@click="btn1......
  • vue-通信
    1、props父子1、Parent.vue//Parent.vue<template> <div> <span>我是Parent组件</span> <Childref="child":parentValue="value"@emitEdit="edit"></Child> ......
  • Vue 子组件修改父组件传递过来的值
    实现效果:通过点击选中的按钮控制左边的树是否进行展示    子组件篇:<el-buttonv-if="isShowTree&hasTree"type="text"icon="btn-arrowiconfontic......
  • vue3+vuex 的 getters 的 使用
     app.vue<template><divclass="app"><h3>在模板中直接使用(vue2-3都可用)</h3>计算:{{$store.getters.counterGetter}}<br/>年龄:......
  • 解决vue使用el-dialog中组件只有第一次执行avue-crud初始话查询方法的问题
    解决方式:在el-dialog标签中加入v-if='dialogVisible',dialogVisible是控制打开el-dialog弹窗的标志<el-dialog:visible.sync="dialogVisible":ap......
  • (Vue)前端获取头文件中的文件内容进行点击下载
    一、需求通过点击按钮下载后端接口头文件中的二进制流文件二、实现1、查看后台接口返回及头文件    这里可以通过content-disposition获取文件名,因......
  • vue3+vuex 的 state 的 使用
     <template><divclass="app"><h3>在模板中直接使用(vue2-3都可用)</h3>姓名:{{$store.state.nameVuex}}等级:{{$store.state.levelVuex}}......
  • vue 获取汉字拼音
    import{pinyin}from'pinyin-pro';//获取带音调拼音pinyin('汉语拼音');//'hànyǔpīnyīn'//获取不带声调的拼音pinyin('汉语拼音',{toneType:'non......