Skip to content

v-price-animate

介绍

v-price-animate 指令用于实现价格变化时的动画效果,通过显示箭头和价格颜色变化来指示价格的上升或下降。

基础方法

vue
<template>
  <div
    v-price-animate="{
      value: number
    }"
  >
    {{ number }}
  </div>
</template>
10000000
查看代码
vue
<script setup lang="ts">
import { vPriceAnimate } from '@cp-vuedir/core'
import { ref } from 'vue';

const number = ref(10000000)
const add = () => {
  number.value += 100
}
const sub = () => {
  number.value -= 100
}
</script>

<template>
  <div class="container">
    <div v-price-animate="{
      value: number,
    }">
      {{ number }}
    </div>
    <div class="button-group">
      <button class="btn" @click="add">+</button>
      <button class="btn" @click="sub">-</button>
    </div>
  </div>
</template>

<style scoped>
.container {
  border: 1px solid #a6aefb;
  border-radius: 12px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 30px;
  flex-direction: column;
}

.button-group {
  display: flex;
  gap: 20px;
  margin-top: 20px;
}

.btn {
  width: 60px;
  height: 40px;
  font-size: 18px;
  border: none;
  border-radius: 6px;
  background-color: #42b883;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.2s;
}

.btn:hover {
  background-color: #358e67;
  transform: scale(1.1);
}

.btn:active {
  background-color: #2c7240;
  transform: scale(1);
}
</style>

自定义颜色

vue
<template>
  <div class="container">
    <div
      v-price-animate="{
        value: number,
        upColor: '#24c5cd',
        downColor: '#180d74'
      }"
    >
      {{ number }}
    </div>
  </div>
</template>
10000000
查看代码
vue
<script setup lang="ts">
import { vPriceAnimate } from '@cp-vuedir/core'
import { ref } from 'vue';

const number = ref(10000000)
const add = () => {
  number.value += 100
}
const sub = () => {
  number.value -= 100
}
</script>

<template>
  <div class="container">
    <div v-price-animate="{
      value: number,
      upColor: '#24c5cd',
      downColor: '#180d74'
    }">
      {{ number }}
    </div>
    <div class="button-group">
      <button class="btn" @click="add">+</button>
      <button class="btn" @click="sub">-</button>
    </div>
  </div>
</template>

<style scoped>
.container {
  border: 1px solid #a6aefb;
  border-radius: 12px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 30px;
  flex-direction: column;
}

.button-group {
  display: flex;
  gap: 20px;
  margin-top: 20px;
}

.btn {
  width: 60px;
  height: 40px;
  font-size: 18px;
  border: none;
  border-radius: 6px;
  background-color: #42b883;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.2s;
}

.btn:hover {
  background-color: #358e67;
  transform: scale(1.1);
}

.btn:active {
  background-color: #2c7240;
  transform: scale(1);
}
</style>

自定义箭头倍率

vue
<template>
  <div
    v-price-animate="{
      value: number,
      arrowSize: 1.5
    }"
  >
    {{ number }}
  </div>
</template>
10000000
查看代码
vue
<script setup lang="ts">
import { vPriceAnimate } from '@cp-vuedir/core'
import { ref } from 'vue';

const number = ref(10000000)
const add = () => {
  number.value += 100
}
const sub = () => {
  number.value -= 100
}
</script>

<template>
  <div class="container">
    <div v-price-animate="{
      value: number,
      arrowSize: 1.5
    }">
      {{ number }}
    </div>
    <div class="button-group">
      <button class="btn" @click="add">+</button>
      <button class="btn" @click="sub">-</button>
    </div>
  </div>
</template>

<style scoped>
.container {
  border: 1px solid #a6aefb;
  border-radius: 12px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 30px;
  flex-direction: column;
}

.button-group {
  display: flex;
  gap: 20px;
  margin-top: 20px;
}

.btn {
  width: 60px;
  height: 40px;
  font-size: 18px;
  border: none;
  border-radius: 6px;
  background-color: #42b883;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.2s;
}

.btn:hover {
  background-color: #358e67;
  transform: scale(1.1);
}

.btn:active {
  background-color: #2c7240;
  transform: scale(1);
}
</style>

API

属性名说明类型是否必选默认值
value
绑定的价格值,支持动态更新
number
-
upColor
价格上涨时显示的颜色
string
#FF4D4F
downColor
价格下降时显示的颜色
string
#52C41A
arrowSize
箭头的大小,控制箭头的显示比例
number
1