joken-前端工程师

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::

测试代码

  • index.vue
<template>
  <div class='box'>
    demo
  </div>
</template>
<script lang='ts' setup>
import { ref, reactive, computed, onMounted, nextTick, PropType } from 'vue';
import useRouterHook from './hooks/helper';
const router = useRouterHook();
</script>
<style lang='scss' scoped></style>
  • hook 函数

//写hook,使用router
import { useRouter } from 'vue-router';

export default function useRouterHook() {
  const router = useRouter();
  console.log(router, 'router沙发斯蒂芬斯蒂芬谁');
  onMounted(() => {
    const router = useRouter();
    console.log(router, 'sdfsdfsdfsdf');
    //router 可以在hook中使用
    /* setTimeout(() => {
      console.log(router, 'sdfsdfsdfsdf2');
      router.push('/pageN');
    }, 3000); */

    /*  router.replace('/pageN'); */
  });
  return router;
}


posted on 2024-11-21 20:59  joken1310  阅读(7)  评论(0编辑  收藏  举报