tabbar.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div class="nut-tabbar" :class="{'bottom':bottom}">
  3. <a class="tabbar-nav"
  4. v-for="(value,index) in tabList"
  5. :class="[{'curr':value.curr},type]"
  6. :key="value.tabTitle"
  7. v-on:click="switchTabs(value,index)"
  8. :href="value.href"
  9. >
  10. <span class="icon-box">
  11. <b class="tips" v-if="value.num">{{value.num}}</b>
  12. <template v-if="value.icon">
  13. <div class="icon" v-if="value.curr" :style="{backgroundImage: 'url('+value.activeIcon+')'}"></div>
  14. <div class="icon" v-else :style="{backgroundImage: 'url('+value.icon+')'}"></div>
  15. </template>
  16. <span :class="['tabbar-nav-word',{'big-word':!value.icon}]">{{value.tabTitle}}</span>
  17. </span>
  18. </a>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name:'nut-tabbar',
  24. props: {
  25. 'tabbarList':{
  26. type:Array,
  27. default:()=>{
  28. return [];
  29. },
  30. },
  31. 'bottom':{
  32. type:Boolean,
  33. default:false,
  34. },
  35. 'type':{
  36. type:String,
  37. default:'based',
  38. }
  39. },
  40. data() {
  41. return {
  42. tabList:this.tabbarList
  43. };
  44. },
  45. watch:{
  46. tabbarList:{
  47. handler(value){
  48. this.tabList = value;
  49. },
  50. deep:true
  51. }
  52. },
  53. methods: {
  54. switchTabs:function(value,index){
  55. let newArr = this.tabList.map((item,idx)=>{
  56. if(index == idx){
  57. item.curr = true;
  58. }else{
  59. item.curr = false;
  60. }
  61. })
  62. this.tabList =newArr;
  63. this.$emit('tab-switch',value,index);
  64. this.$emit('tabSwitch',value,index); //兼容以前驼峰法
  65. }
  66. },
  67. }
  68. </script>