Vue组件(点击返回顶部)

news/2024/7/9 23:56:22 标签: vue
  1. 在components文件夹下创建 ClientHeight.vue 和 index.js 文件
 //ClientHeight.vue配置
<template>
    <div class="th-back-top" v-show="flag" @click="clickHidden">
        <span class="bg-back2top2"></span>
    </div>
</template>
<script>
export default {
    name:"BackTop",
    data(){
        return{
            flag:false
        }
    },
    mounted(){
        // console.log(window.document.documentElement.clientHeight);  //获取页面可视化高度

       window.addEventListener("scroll",()=>{
        //    console.log(document.documentElement.scrollTop);  //获取页面滚动的高度
           let scrollTop = document.documentElement.scrollTop;
           if(scrollTop > 100){
               this.flag = true;
           }else{
               this.flag = false;
           }

       }) 
    },
    methods:{
       clickHidden(){
           document.documentElement.scrollTop = 0;   //点击返回顶部
       }
    }
}
</script>
<style scoped>

.th-back-top{
    position:fixed;
    right:15px;
    bottom:104px;
    height: 39px;
    width: 80px;
    z-index:9;
    opacity:0.8;
    text-align:right;
}
.bg-back2top2 {
    display: inline-block;
    background: url(//static1.qianqian.com/web/st/images/icon-back2top2.af69f845890e1a53.png)
        no-repeat 0 0;
    -webkit-background-size: 39px 39px;
    background-size: 39px 39px;
    width: 39px;
    height: 39px;
}
</style>
  1. 同级 index.js 导出
import ClientHeight from './AA/ClientHeight'
export default (Vue)=>{
    Vue.component(ClientHeight.name,ClientHeight);
}
  1. main.js 文件引入
import ClientHeight from './components/ClientHeight/index'
Vue.use(ClientHeight);
  1. App 中使用 :<ClientHeight/>

http://www.niftyadmin.cn/n/1813799.html

相关文章

CentOS6下配置本地用户访问vsftpd,并赋予写权限

这段时间用到了linux下的ftp&#xff0c;上网搜搜问题解决了。可网上资料有点乱&#xff0c;决定把自己的配置过程记录下来&#xff0c;也方便我以后查看。 一、安装并测试可用性 1、安装命令 yum install vsftpd 2、配置防火墙 3、配置服务 配置开机启动 启动服务&#xff1a;…

c#/c++ 通过系统api监视文件变化的问题

再分享个比较经典的案例&#xff0c;在很多场景下&#xff0c;我们都要去监视某个文件夹下的文件变化&#xff0c;在创建、修改或删除的时候触发一些行为。众所周知&#xff0c;c#有个实现类叫FileSystemWatcher&#xff0c;可以用来监视目录包括子目录下文件的变化&#xff0c…

ES6随笔(重点)

ES6新增块级作用域概念。let和const声明的变量和常量&#xff0c;只在所处的代码块内有效&#xff0c;外部访问打印 x is not defined. 最典型的就是for循环中的变量声明&#xff0c;用var声明的话&#xff0c;i是全局变量&#xff0c;每一次循环i的值都增加&#xff0c;所以在…

SVN协同开发工具随笔

协同开发工具(版本控制器) 目前使用最广泛的就是svn和git 主要作用&#xff1a;管理项目的版本&#xff0c;多人协同开发 svn 和 git 帮我们管理项目 svn&#xff1a;集中式 git&#xff1a;分布式 SVN 安装SVN 打开服务器&#xff1a; 注意事项&#xff1a;svn的服务器默认…

Git协同开发工具随笔

协同开发工具(版本控制器) 目前使用最广泛的就是svn和git 主要作用&#xff1a;管理项目的版本&#xff0c;多人协同开发 List item svn和git帮我们管理项目 svn&#xff1a;集中式 git&#xff1a;分布式 Git 参考站点&#xff1a;https://www.liaoxuefeng.com/wiki/89604…

android 对话框

<?xml version"1.0" encoding"utf-8"?><LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:id"id/ok"android:layout_width"fill_parent"android:layout_height"fill_parent…

CentOS 5: Make Command not Found

在centos 5下安装软件遇到的问题&#xff0c;google了一圈&#xff0c;是因为系统没有安装编译器&#xff0c;那安装就是了&#xff0c;嘿嘿。解决办法&#xff0c;在SSH下输入下面的命令 yum -y install gcc automake autoconf libtool make 转载于:https://www.cnblogs.com/r…

远程仓库之码云(gitee)

Github(全球最大的代码托管平台)。https://github.com/这个网站就是提供Git仓库托管服务的。由于你的本地Git仓库和GitHub仓库之间的传输是通过SSH加密的&#xff0c;所以&#xff0c;需要一点设置&#xff1a; 创建SSH Key。 在用户主目录下&#xff0c;看看有没有.ssh目录&am…