zoukankan      html  css  js  c++  java
  • Vue获取DOM元素的属性值

     项目中需要做一个小弹层,如下图:

    我需要知道点击元素距离顶部的值,再计算弹层的top值,如下图:

    在vue中如何获取到DOM元素距离窗口顶部的值呢?

    1.通过$event获取

    html:

    <div class="sort-item" @click="showFilter($event)">
        {{currentFilter}}
        <div class="sort-icon">
            <i class="iconfont icon-shaixuan"></i>
        </div>
    </div>

    methods:

    showFilter: function ($event) {
        this.filterShow = true;
        this.popoverShow = true;
        this.filterPosTop = $event.currentTarget.getBoundingClientRect().top;
    },

    如下图:

    2.通过this.$refs.***获取

    1.目标DOM定义ref值:

    2.通过 【this.$refs.***.属性名】 获取相关属性的值:

  • 相关阅读:
    Redis篇
    MySql篇
    Tomcat篇
    JDK篇
    冒泡排序(算法源码)
    堆排序(源码)
    快速排序(递归及非递归算法源码)
    MongoDB 复制
    MongoDB appendix
    服务器端脚本
  • 原文地址:https://www.cnblogs.com/sese/p/9995591.html
Copyright © 2011-2022 走看看