服务器之家:专注于服务器技术及软件下载分享
分类导航

node.js|vue.js|jquery|angularjs|React|json|js教程|

服务器之家 - 编程语言 - JavaScript - vue.js - vue实现卡片翻转轮播展示

vue实现卡片翻转轮播展示

2022-01-10 16:42Cardhu丶 vue.js

这篇文章主要为大家详细介绍了vue实现卡片翻转轮播展示,同时在翻转时切换数据,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

vue卡片翻转轮播展示,同时在翻转时切换数据,供大家参考,具体内容如下

效果及代码

vue实现卡片翻转轮播展示

代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<template>
  <div class="list-container">
    <div class="reason" v-if="list1.length > 0 || list2.length > 0">
      <div class="logo">
        <svg-icon class="center-svg" icon-class="centerLogo"></svg-icon>
        <div class="echart">
          <echart :option="option" echartId="roadP" />
        </div>
      </div>
      <RoadComponent :list="list1[0]" :style="{ display: show1 }"></RoadComponent>
      <RoadComponent :list="list2[0]" :style="{ display: show2 }"></RoadComponent>
      <RoadComponent :list="list1[1]" :style="{ display: show3 }"></RoadComponent>
      <RoadComponent :list="list2[1]" :style="{ display: show4 }"></RoadComponent>
      <RoadComponent :list="list1[2]" :style="{ display: show5 }"></RoadComponent>
      <RoadComponent :list="list2[2]" :style="{ display: show6 }"></RoadComponent>
    </div>
  </div>
</template>
<script>
  import { defineComponent, inject, onMounted, reactive, onUnmounted, toRefs } from 'vue';
  import { congestionPredict } from '@/apis/fullView';
  import echart from '@/components/common/echart';
  import '@/assets/icons/fullView/westToEast.svg';
  import '@/assets/icons/fullView/eastToWest.svg';
  import '@/assets/icons/fullView/northToSouth.svg';
  import '@/assets/icons/fullView/southToNorth.svg';
  import '@/assets/icons/fullView/centerLogo.svg';
  import RoadComponent from '@/views/fullView/left/RoadComponent';
  export default defineComponent({
    name: 'RoadP',
    components: { echart, RoadComponent },
    setup() {
      let echarts = inject('ec');
      const dataMap = reactive({
        interval: null,
        interval1: null,
        list1: [],
        list2: [],
        list: [],
        option: {},
        timeout: 10,
        show1: 'block',
        show2: 'none',
        show3: 'block',
        show4: 'none',
        show5: 'block',
        show6: 'none',
      });
      onMounted(() => {
        getData();
        dataMap.interval = setInterval(() => {
          getData();
        }, 60 * 1000);
        dataMap.interval1 = setInterval(() => {
          if (dataMap.timeout > 8 && dataMap.timeout < 11) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'block';
            dataMap.show5 = 'block';
            dataMap.show2 = 'none';
            dataMap.show4 = 'none';
            dataMap.show6 = 'none';
          } else if (dataMap.timeout === 8) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'none';
            dataMap.show3 = 'block';
            dataMap.show5 = 'block';
            dataMap.show2 = 'block';
            dataMap.show4 = 'none';
            dataMap.show6 = 'none';
          } else if (dataMap.timeout === 7) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'none';
            dataMap.show3 = 'none';
            dataMap.show5 = 'block';
            dataMap.show2 = 'block';
            dataMap.show4 = 'block';
            dataMap.show6 = 'none';
          } else if (dataMap.timeout < 7 && dataMap.timeout > 3) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'none';
            dataMap.show3 = 'none';
            dataMap.show5 = 'none';
            dataMap.show2 = 'block';
            dataMap.show4 = 'block';
            dataMap.show6 = 'block';
          } else if (dataMap.timeout === 3) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'none';
            dataMap.show5 = 'none';
            dataMap.show2 = 'none';
            dataMap.show4 = 'block';
            dataMap.show6 = 'block';
          } else if (dataMap.timeout === 2) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'block';
            dataMap.show5 = 'none';
            dataMap.show2 = 'none';
            dataMap.show4 = 'none';
            dataMap.show6 = 'block';
          } else if (dataMap.timeout === 1) {
            dataMap.timeout = dataMap.timeout - 1;
            dataMap.show1 = 'block';
            dataMap.show3 = 'block';
            dataMap.show5 = 'block';
            dataMap.show2 = 'none';
            dataMap.show4 = 'none';
            dataMap.show6 = 'none';
          } else {
            dataMap.timeout = 10;
          }
        }, 1000);
      });
      onUnmounted(() => {
        clearInterval(dataMap.interval);
        clearInterval(dataMap.interval1);
      });
      const getData = () => {
        congestionPredict()
          .then((res) => {
            if (res && res.code === 0 && res.data) {
              dataMap.list1 = [];
              dataMap.list2 = [];
              for (let i = 0; i < 6; i = i + 2) {
                dataMap.list1.push([
                  {
                    name: res.data[i].name,
                    direction: res.data[i].direction,
                    value: res.data[i].index.toFixed(1),
                    icon: res.data[i].englishDirection,
                  },
                  {
                    name: res.data[i + 1].name,
                    direction: res.data[i + 1].direction,
                    value: res.data[i + 1].index.toFixed(1),
                    icon: res.data[i + 1].englishDirection,
                  },
                ]);
              }
              for (let j = res.data.length - 1; j > res.data.length - 6; j = j - 2) {
                dataMap.list2.push([
                  {
                    name: res.data[j].name,
                    direction: res.data[j].direction,
                    value: res.data[j].index.toFixed(1),
                    icon: res.data[j].englishDirection,
                  },
                  {
                    name: res.data[j - 1].name,
                    direction: res.data[j - 1].direction,
                    value: res.data[j - 1].index.toFixed(1),
                    icon: res.data[j - 1].englishDirection,
                  },
                ]);
              }
            }
          })
          .catch((err) => {
            console.log(err);
          })
          .finally(() => {
            dataMap.option = getOption();
          });
      };
 
      const getOption = () => {
        return {
          series: [
            {
              type: 'liquidFill',
              name: '',
              radius: '85%',
              center: ['50%', '45%'],
              data: [0.55, 0.5, 0.5],
              color: ['rgba(0,118,255,0.5)', 'rgba(0,102,255,0.5)', 'rgba(0,185,255,0.6)'],
              outline: {
                show: false,
              },
              backgroundStyle: {
                color: 'transparent',
                borderColor: 'transparent',
                borderWidth: 1,
                shadowColor: 'transparent',
                shadowBlur: 0,
              },
              label: {
                show: false,
              },
            },
          ],
        };
      };
      return {
        ...toRefs(dataMap),
      };
    },
  });
</script>
<style scoped lang="less">
  .list-container {
    width: 100%;
    height: 280px;
  }
  .reason {
    width: 696px;
    margin: 16px auto;
    height: 228px;
    position: relative;
    list-style: none;
    .logo {
      width: 150px;
      height: 150px;
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
      background: url('~@/assets/img/fullView/centerGround.dynamic.png');
      background-size: 100% 100%;
    }
    .echart {
      width: 158px;
      height: 158px;
      position: absolute;
      left: -4px;
      top: 4px;
    }
  }
  .center-svg {
    width: 90px;
    height: 100px;
    position: absolute;
    left: 30px;
    top: 25px;
    z-index: 15;
  }
</style>

卡片组件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template>
  <div class="goBack" v-if="list.length > 0">
    <div class="top">
      <svg-icon class="svg" :icon-class="list[0].icon"></svg-icon>
      <div>
        <div>
          <p class="span-container text-overflow">{{ list[0].name }}</p>
          <p class="index" :style="{ color: switchColor(list[0].value) }">{{ list[0].value }}</p>
        </div>
        <div>
          <p class="span-container text-overflow">{{ list[1].name }}</p>
          <p class="index" :style="{ color: switchColor(list[1].value) }">{{ list[1].value }}</p>
        </div>
      </div>
      <svg-icon class="svg" :icon-class="list[1].icon"></svg-icon>
    </div>
  </div>
</template>
<script>
  import { defineComponent } from 'vue';
 
  export default defineComponent({
    name: 'RoadComponent',
    props: {
      list: {},
    },
    setup() {
      const switchColor = (value) => {
        if (value > 0 && value <= 2) {
          return '#00DBEB';
        } else if (value > 2 && value <= 3) {
          return '#FFD200';
        } else if (value > 3 && value <= 4) {
          return '#FF7309';
        } else if (value > 4 && value <= 5) {
          return '#FF0000';
        }
      };
      return {
        switchColor,
      };
    },
  });
</script>
<style lang="less" scoped>
  .goBack {
    transform-style: preserve-3d;
    animation: back 0.5s linear 1;
  }
  .back:hover {
    animation-play-state: paused;
  }
  @keyframes back {
    0% {
      transform: rotateZ(0deg) rotateY(0deg) rotateX(-90deg);
    }
    100% {
      transform: rotateZ(0deg) rotateY(0deg) rotateX(0deg);
    }
  }
  .span-container {
    width: 150px;
    margin: 0 0 5px 5px;
    color: var(--text-blue);
    font-size: var(--font-traffic-size);
  }
  .svg {
    width: 41px;
    height: 41px;
  }
  .top {
    display: flex;
    flex-wrap: nowrap;
    padding: 0 20px;
    margin: 0 0 14px 0;
    justify-content: space-between;
    align-items: center;
    height: 68px;
    border-radius: 10px;
    opacity: 0.9;
    background: linear-gradient(
      89deg,
      rgba(0, 76, 169, 0.5) 0%,
      rgba(0, 76, 169, 0) 46%,
      rgba(0, 76, 169, 0) 49%,
      rgba(0, 76, 169, 0) 52%,
      rgba(0, 76, 169, 0.5) 100%
    );
  }
  .top > div {
    width: 640px;
    display: flex;
    text-align: center;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: space-between;
    & > div {
      width: 160px;
      span {
        margin-left: 15px;
      }
    }
    .index {
      width: 155px;
      height: 28px;
      font-size: var(--font-size-chart-title);
      text-align: center;
      margin: 0;
      line-height: 28px;
    }
  }
</style>

关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。

精彩专题分享:jQuery图片轮播 JavaScript图片轮播 Bootstrap图片轮播

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/weixin_43996368/article/details/117778558

延伸 · 阅读

精彩推荐
  • vue.jsVue多选列表组件深入详解

    Vue多选列表组件深入详解

    这篇文章主要介绍了Vue多选列表组件深入详解,这个是vue的基本组件,有需要的同学可以研究下...

    yukiwu6752022-01-25
  • vue.js梳理一下vue中的生命周期

    梳理一下vue中的生命周期

    看过很多人讲vue的生命周期,但总是被绕的云里雾里,尤其是自学的同学,可能js的基础也不是太牢固,听起来更是吃力,那我就已个人之浅见,以大白话...

    CRMEB技术团队7992021-12-22
  • vue.jsVue2.x 项目性能优化之代码优化的实现

    Vue2.x 项目性能优化之代码优化的实现

    这篇文章主要介绍了Vue2.x 项目性能优化之代码优化的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋...

    优小U9632022-02-21
  • vue.js详解vue 表单绑定与组件

    详解vue 表单绑定与组件

    这篇文章主要介绍了vue 表单绑定与组件的相关资料,帮助大家更好的理解和学习使用vue框架,感兴趣的朋友可以了解下...

    Latteitcjz6432022-02-12
  • vue.jsVue项目中实现带参跳转功能

    Vue项目中实现带参跳转功能

    最近做了一个手机端系统,其中遇到了父页面需要携带参数跳转至子页面的问题,现已解决,下面分享一下实现过程,感兴趣的朋友一起看看吧...

    YiluRen丶4302022-03-03
  • vue.js用vite搭建vue3应用的实现方法

    用vite搭建vue3应用的实现方法

    这篇文章主要介绍了用vite搭建vue3应用的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下...

    Asiter7912022-01-22
  • vue.jsVue2.x-使用防抖以及节流的示例

    Vue2.x-使用防抖以及节流的示例

    这篇文章主要介绍了Vue2.x-使用防抖以及节流的示例,帮助大家更好的理解和学习使用vue框架,感兴趣的朋友可以了解下...

    Kyara6372022-01-25
  • vue.jsVue中引入svg图标的两种方式

    Vue中引入svg图标的两种方式

    这篇文章主要给大家介绍了关于Vue中引入svg图标的两种方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的...

    十里不故梦10222021-12-31