e.target--- dom事件对象event

event不会事件冒泡,值作用于此节点对象,不会传递到父节点或子节点

标准属性:

属性描述
bubbles返回布尔值,指示事件是否是起泡事件类型。
cancelable返回布尔值,指示事件是否可拥可取消的默认动作。
currentTarget返回其事件监听器触发该事件的元素。
eventPhase返回事件传播的当前阶段。
target返回触发此事件的元素(事件的目标节点)。
timeStamp返回事件生成的日期和时间。
type返回当前 Event 对象表示的事件的名称。

使用方法:

e.target

例如:获取节点的内容e.target.innerHTML  或者 e.targert.innerText

handleLetterClick(e) {
   this.$emit('change', e.target.innerText)
},

示例组件

<template>
  <ul class="list">
    <li
      class="item"
      v-for="item of letters"
      :key="item"
      :ref="item"
      @touchstart="handleTouchStart"
      @touchmove="handleTouchMove"
      @touchend="handleTouchEnd"
      @click="handleLetterClick"
    >{{item}}</li>
  </ul>
</template>

<script>
  export default {
    name: "CityAlphabet",
    props: {
      cities: Object
    },
    computed: {
      letters() {
        const letters = []
        for (let i in this.cities) {
          letters.push(i)
        }
        return letters
      }
    },
    data() {
      return {
        touchStatus: false
      }
    },
    methods: {
      handleLetterClick(e) {
        this.$emit('change', e.target.innerHTML)
      },
      // handleTouch...系列方法是 手指在手机屏幕的右侧字母滑动时,左侧城市列表跟着变化,可以不增加此功能,只有点击字母表城市列表变化也很合理
      handleTouchStart() {
        this.touchStatus = true
      },
      handleTouchMove(e) {
        if (this.touchStatus) {
          // A字母到input框的距离
          const startY = this.$refs['A'][0].offsetTop
          //手指位置到input的距离 = 手指位置距离顶部位置 - header
          const touchY = e.touches[0].clientY - 79
          // 当前手指的字母位置
          const index = Math.floor((touchY - startY) / 20)
          if (index >= 0 && index < this.letters.length) {
            this.$emit('change', this.letters[index])
          }
        }
      },
      handleTouchEnd() {
        this.touchStatus = false
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import '~styles/varibless.styl'
 .list
   display flex
   flex-direction column
   justify-content center
   position absolute
   right 0
   top 1.58rem
   bottom 0
   width .4rem
   .item
     line-height .4rem
     text-align center
     color $bgColor
</style>

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值