Vue uniapp realizes the segmenter effect

Vue uniapp realizes the segmenter effect

This article shares the specific code of vue uniapp to achieve the segmenter effect for your reference. The specific content is as follows

This is just to record the effect of dynamically changing the style with vue

Show the effect first

Template

<view class="countTime">
 <text class="title">Discounts and dining hours</text>
 <view class="wrap">
  <view class="box" v-for="(item,index) in discountList" :key="index" @click="toggleItem(index)">
   <view class="selBox" :style="[itemStyle(index)]">
    <view class="countBox">
     <text class="count">{{item.count}}</text>
     <text>Fold</text>
       </view>
    <text class="time">{{item.time}}</text>
   </view> 
   <text class="countPrice" :style="[priceStyle(index)]">After discount, average price per person is ¥100</text>
  </view>
 </view>
</view>

Script part

The key to this part is the code under computed

export default {
  data() {
   return {
    themColor:this.Enum.Them.base,
    discountList:[{
     "count":6.9,
     "time":"12:00~13:00"
    },{
     "count":6.7,
     "time":"14:00~16:00"
    },{
     "count":6.5,
     "time":"20:00~22:00"
    }],
    currentIndex:0
   }
  },
  computed:{
   itemStyle(){
    return index => {
     let style = {}
     if(index === this.currentIndex){
      style.backgroundColor = this.themColor;
      style.border = `1px solid ${this.themColor}`;
      style.color = '#fff';
     }
     //When the second one is selected, the first right border and the third left border are set to none
     if(this.currentIndex === 1){
      if(index === this.currentIndex - 1){
       style.borderRight = 'none !important'
      }
      if(index === this.currentIndex + 1){
       style.borderLeft = 'none !important'
      }
     }
     return style
    }
   },
   priceStyle(){
    return index => {
     let style = {}
     if(index === this.currentIndex){
      style.color = this.themColor
     }
     return style
    }
   }
  },
  methods: {
   toggleItem(idx){
    this.currentIndex = idx
   }
  }
 }

CSS Styles

The scss used here will not be described in detail here.

.countTime{
  display: flex;
  flex-direction: column;
  .title{
   font-size: $uni-font-size-bl;
   margin: 20rpx 0;
  }
  .wrap{
   display: flex;
   .box{
    @include flex(column,center,center);
    width: 33%;
    &:nth-child(2){
     & > .selBox{
      border-left: none;
      border-right: none;
     }
    }
    .selBox{
     @include flex(column,center,center);
     width: 100%;
     height: 150rpx;
     border: 1px solid $uni-border-color;
     .countBox{
      font-size: $uni-font-size-lg;
      font-weight: bold;
      margin-bottom: 10rpx;
      .count{
       font-size: $uni-font-size-bl;
      }
     }
     .time{
      font-size: $uni-font-size-l;
     }
    }
    .countPrice{
     margin-top: 10rpx;
     font-size: $uni-font-size-l;
    }
   }
  }
 }

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Analysis of uniapp entry-level nvue climbing pit record
  • Based on vue+uniapp live broadcast project, uni-app imitates Douyin/Momo live broadcast room function
  • Detailed explanation of the difference between uniapp and vue

<<:  MySql8 WITH RECURSIVE recursive query parent-child collection method

>>:  How to modify the contents of an existing Docker container

Recommend

Detailed analysis of javascript data proxy and events

Table of contents Data Brokers and Events Review ...

MySQL variable declaration and stored procedure analysis

Declaring variables Setting Global Variables set ...

In-depth explanation of nginx location priority

location expression type ~ indicates to perform a...

Solution to the problem of invalid width setting for label and span

By default, setting width for label and span is in...

12 Useful Array Tricks in JavaScript

Table of contents Array deduplication 1. from() s...

CentOS 6.4 MySQL 5.7.18 installation and configuration method graphic tutorial

The specific steps of installing mysql5.7.18 unde...

Docker installs redis 5.0.7 and mounts external configuration and data issues

Redis is an open source NoSQL database written in...

Detailed explanation of the use of MySQL paradigm

1. Paradigm The English name of the paradigm is N...

Windows cannot start MySQL service and reports error 1067 solution

Suddenly when I logged into MySQL, it said that a...

CentOS method to modify the default ssh port number example

The default ssh port number of Linux servers is g...

32 Typical Column/Grid-Based Websites

If you’re looking for inspiration for columnar web...

Python MySQL database table modification and query

Python connects to MySQL to modify and query data...

Getting Started Tutorial for Beginners ④: How to bind subdirectories

To understand what this means, we must first know ...