VUE 选项卡跳转

本文记录了在Vue.js中实现选项卡切换的两种常见方法:通过router跳转和直接使用components。在router跳转中,涉及app.vue的router-view配置、main.js的引用以及Tabbar.vue组件。而在纯用components的方式下,详细说明了组件的切换过程。
摘要由CSDN通过智能技术生成

刚接触vue不久,就遇上了tab(之前只用过js),在查阅网上资料并运行代码后,发现用router跳转和直接components选择切换是最普遍的方法。以下代码是在原本大佬的基础上修改的,就不作为原创啦,但原文网址找不到啦,现在作为一个简单的笔记记录一下(毕竟真的很简单且常用)。

一、通过router跳转

 

1.app.vue 总的router-view设置

<template>
  <div id="app">
    <router-view></router-view>
    <tabbar v-if="$route.meta.showTab"></tabbar>
  </div>
</template>

<script>
import Tabbar from "./components/Tabbar";
export default {
  name: "app",
  created: function () {
    this.$router.push("/");
  },
  components: {
    Tabbar,
  },
};
</script>

1.main.js中引用 

import Vue from "vue";
import App from "./App.vue";
import router from "./router/index.js";
import VueRouter from "vue-router";
import MintUI from "mint-ui";
import "mint-ui/lib/style.css";
import axios from "axios";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import Vant from "vant";
import "vant/lib/index.css";
import VueResource from "vue-resource";//上下包含了其他组件库,按需引入

Vue.use(VueResource);
Vue.use(Vant);
Vue.use(ElementUI);
Vue.prototype.$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值