vue首页引用导航组件

 

<!-- 首页页面 -->
<div id="app">
  <div id="container">
    <Shouye index="0"></Shouye>
  </div>
</div>
<script>
import Shouye from '/导航组件.html'
 var testVue = new Vue({
    el:'#app',
    data(){
      return {
        tabActive:0,
      }
    },
    components:{
      Shouye
    },
    methods : {

    },

 });

</script>
<style >
body{
  padding:0;margin:0;
  width:100%;
  list-style: none;
  text-decoration: none;
  margin:0;
}
ul{
  margin:0;
  padding: 0;
}
p{
  margin:0 0;
}
#container{
  width:100%;
  height:100%;
}
#container .contHead{
  width:100%;
  overflow: hidden;
}
#container .contHead .li{
  width:25%;
  height:40px;
  float: left;
  list-style: none;
  line-height:40px;
  text-align: center;
  display: block;
}
#container .contHead .show{
  border-bottom: 2px solid #30BEC1;
}
</style>

 

<!-- 导航组件 -->
<div id="app">
  <div id="container">
    <div class="contHead">
      <ul>
        <router-link class="li" :class="{show:tabActive[0]}" :to="{path:'/首页.html'}">首页</router-link>
        <router-link class="li" :class="{show:tabActive[1]}" >冬装</router-link>
        <router-link class="li" :class="{show:tabActive[2]}">男装</router-link>
        <router-link class="li" :class="{show:tabActive[3]}">女装</router-link>
      </ul>
    </div>
  </div>
</div>
<script>
 var testVue = new Vue({
    el:'#app',
    props:[
      index:0
    ],
    data(){
      return {
        tabActive:[false,false,false,false]
      }
    },
    methods : {
      tab(index){
        for(var i=0;i<this.tabActive.length;i++){
          if(i==index){
            this.tabActive[i] = true
          }else{
            this.tabActive[i] = false
          }
        }
      },
    },
    created() {
        this.tab(this.index)
    }
 });

</script>
<style >
body{
  padding:0;margin:0;
  width:100%;
  list-style: none;
  text-decoration: none;
  margin:0;
}
ul{
  margin:0;
  padding: 0;
}
p{
  margin:0 0;
}
#container{
  width:100%;
  height:100%;
}
#container .contHead{
  width:100%;
  overflow: hidden;
}
#container .contHead .li{
  width:25%;
  height:40px;
  float: left;
  list-style: none;
  line-height:40px;
  text-align: center;
  display: block;
}
#container .contHead .show{
  border-bottom: 2px solid #30BEC1;
}
</style>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3中的组件路由导航守卫有三个状态:beforeRouteEnter、beforeRouteUpdate和beforeRouteLeave。\[1\]在组件内部,可以通过在methods中定义这些守卫函数来实现对应的功能。在beforeRouteEnter中,可以在渲染该组件的对应路由被确认之前执行一些操作。在beforeRouteUpdate中,可以在当前路由改变但是该组件被复用时执行一些操作。在beforeRouteLeave中,可以在导航离开该组件的对应路由时执行一些操作。\[3\] 另外,在路由配置文件router\index.js中,也可以使用全局的路由守卫函数来实现对应的功能。在beforeEach函数中,可以在每次路由跳转之前执行一些操作,比如打印跳转的目标路由信息。然后通过调用next()函数来继续跳转,或者通过返回false来禁止跳转。\[2\] 总结起来,Vue 3中的组件路由导航守卫可以通过在组件内部定义守卫函数或者在路由配置文件中使用全局的守卫函数来实现,在不同的守卫状态下执行对应的操作。 #### 引用[.reference_title] - *1* *2* [Vue——vue3路由导航守卫及其写法](https://blog.csdn.net/qq_43201350/article/details/127220103)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [vue路由导航守卫(全局守卫、路由独享守卫、组件内守卫)](https://blog.csdn.net/m0_64590669/article/details/129306681)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值