vue制作tab切换(vuex + 动画)
生活随笔
收集整理的這篇文章主要介紹了
vue制作tab切换(vuex + 动画)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
先來看一下效果
這里使用了vuex 來處理數據。
(1)在首頁選擇的時候,將選擇的結果存入state里面。
(2)進入到內部頁面,再將state的值 賦值給當前要切換tab。
這里只寫一下內部tab的代碼,順便解釋一下:
<template><div class="menu"><ul class="tab-tilte"><liv-for="(title, index) in tabTitle":key="`tilte_${index}`":class="{ active: cur == index }">{{ title }}</li></ul><div class="tab-content"><divv-for="(m, index) in tabMain"v-show="cur == index":key="`content_${index}`">{{ m }}</div></div></div> </template> <script> import { mapState, mapMutations, mapActions } from "vuex"; export default {data() {return {tabTitle: ["回到首頁", "大賽介紹", "作品列表", "我要投稿"],tabMain: ["內容一", "內容二", "內容三", "內容四"],cur: 1 //默認選中第一個tab};},computed: {...mapState(["selectTab"])},mounted() {this.cur = this.selectTab;},methods: {changeIndex(index) {this.changeLink(index);this.cur = index;}} }; </script> <style lang="scss" scoped> @import "../../../../style/base"; .menu {width: 100%; } .tab-tilte {width: 100%;padding: 14px 22px;display: flex;justify-content: space-between; } .tab-tilte li {padding: 10px 10px;text-align: center;background-color: #f4f4f4;cursor: pointer;width: 70px;height: 70px;font-size: 18px;text-align: center;border-radius: 8px; } /* 點擊對應的標題添加對應的背景顏色 */ .tab-tilte .active {background-color: #09f;color: #fff; } .tab-content div {// float: left;// width: 25%;line-height: 100px;text-align: center; } </style>selectTab是第一次 在主界面,點擊三個菜單選擇的值,這里存儲1,2,3 。進入到內部頁面,再將值付給當前的cur.
總結
以上是生活随笔為你收集整理的vue制作tab切换(vuex + 动画)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue路由query和params的区别
- 下一篇: 脉脉如何隐藏个人信息