vue 实现三秒钟倒计时 跳转页面

DOM节点: <span>{{count}}</span>
data() {
return{
count:''
}
},
created() {
    this.countDown() // 倒计时
  },
  methods: {
    countDown() {
      const TIME_COUNT = 3
      if (!this.timer) {
        this.count = TIME_COUNT
        this.timer = setInterval(() => {
          if (this.count > 1 && this.count <= TIME_COUNT) { //限制倒计时区间
            this.count--
          } else {
            clearInterval(this.timer)   //删除定时器
            this.timer = null
            //跳转的页面写在此处
            this.$router.push('/vaccineProtectionTk')
          }
        }, 1000)
      }
    },
  },
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue3可以通过vue-router实现三级页面跳转。具体实现方式如下: 1. 首先需要安装vue-router,可以通过npm进行安装:`npm install vue-router` 2. 在Vue的入口文件中引入vue-router并注册: ``` import { createRouter, createWebHashHistory } from 'vue-router' import Home from './views/Home.vue' import Category from './views/Category.vue' import Product from './views/Product.vue' const routes = [ { path: '/', name: 'Home', component: Home }, { path: '/category', name: 'Category', component: Category }, { path: '/product/:id', name: 'Product', component: Product } ] const router = createRouter({ history: createWebHashHistory(), routes }) export default router ``` 这里我们定义了三个路由:首页、分类页和商品详情页。其中商品详情页的路由中包含了一个参数id,用于显示不同的商品详情。 3. 在Vue组件中使用路由跳转: ``` <template> <div> <h1>分类页</h1> <ul> <li v-for="item in categoryList" :key="item.id"> <router-link :to="{name:'Product',params:{id:item.id}}">{{item.name}}</router-link> </li> </ul> </div> </template> <script> export default { data() { return { categoryList: [ { id: 1, name: '商品1' }, { id: 2, name: '商品2' }, { id: 3, name: '商品3' } ] } } } </script> ``` 这里我们在分类页中使用了`router-link`组件来跳转到商品详情页,通过`:to`属性设置路由的名称以及参数id。 4. 在商品详情页中获取参数并显示对应的内容: ``` <template> <div> <h1>商品详情页</h1> <p>{{product.name}}</p> <p>{{product.desc}}</p> </div> </template> <script> export default { data() { return { product: {} } }, created() { const productId = this.$route.params.id // 根据productId获取商品详情,并将数据赋值给product this.product = { id: productId, name: '商品' + productId, desc: '这是商品' + productId + '的描述' } } } </script> ``` 这里我们通过`this.$route.params.id`获取到路由中的参数id,并根据该参数获取对应的商品详情数据,并将数据赋值给`product`。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值