PC页面底部点击返回顶部

首先在 mounted中写入:

 mounted() {

       window.addEventListener("scroll", this.handleScroll, true);

    },

methods中写入:

 

methods:{

        

 handleScroll() {

      let scrolltop =document.documentElement.scrolltop || document.body.scrollTop;

      scrolltop > 30 ? (this.gotop = true) : (this.gotop = false);

     },

     toTop() {

      let top = document.documentElement.scrollTop || document.body.scrollTop;

      const timeTop = setInterval(() => {

        document.body.scrollTop = document.documentElement.scrollTop = top -= 50;

        if (top <= 0) {

          clearInterval(timeTop);

        }

      }, 10);

    }

}

其中toTop是点击事件的名称,即可完成返回顶部。

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Vue.js中,要实现点击按钮跳转页面的功能,你可以使用Vue Router来管理页面路由。下面是一个简单的示例: 首先,确保已经安装了Vue Router。你可以使用以下命令进行安装: ``` npm install vue-router ``` 然后,在你的Vue项目中创建一个新的Vue Router实例并配置路由。例如,在`router.js`文件中: ```javascript import Vue from 'vue'; import Router from 'vue-router'; // 导入需要跳转的页面组件 import HomePage from '@/components/HomePage'; import AboutPage from '@/components/AboutPage'; Vue.use(Router); export default new Router({ routes: [ { path: '/', name: 'home', component: HomePage, }, { path: '/about', name: 'about', component: AboutPage, }, ], }); ``` 在这个示例中,我们定义了两个路由,分别对应`HomePage`和`AboutPage`组件。 接下来,在你的Vue组件中,你可以使用`<router-link>`标签来创建一个按钮,并设置它的`to`属性为目标页面的路径。例如,在一个名为`ButtonComponent`的组件中: ```vue <template> <div> <router-link to="/about"> <button>跳转到关于页面</button> </router-link> </div> </template> <script> export default { name: 'ButtonComponent', }; </script> ``` 在这个示例中,当用户点击这个按钮时,会自动跳转到`/about`路径对应的页面。 最后,确保在你的Vue根组件中使用了`<router-view>`标签来渲染路由组件。例如,在`App.vue`文件中: ```vue <template> <div id="app"> <router-view></router-view> </div> </template> <script> export default { name: 'App', }; </script> ``` 这样,当用户点击按钮时,就会根据路由配置跳转到相应的页面。 希望这个示例能帮助到你实现按钮点击跳转页面的功能!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值