我正在学习过渡如何与 vue 一起工作。我有一个价格估算,当点击每个选项卡时,它会显示每件商品的估算价格。我希望当项目出现时,有一个向下滑动的效果。我试图找出方法,并通过Enter / Leave & List Transitions找到了方法。而且我也尝试过,但是效果还是不行。谁能帮我解决这个问题?
我在 Codesandbox 中的完整代码 => https://codesandbox.io/s/suspicious-almeida-rjyy9
PriceEstimation.vue
<template>
<div class="card">
<div class="card-header">Price Estimation</div>
<div class="card-body px-0 pt-0">
<transition name="slide">
<div class="estimation-category" v-if="cart.total || isDropped">
<div v-if="cart.storage && cart.storage.totalCost">
<div class="bg-secondary d-flex justify-content-between p-2">
<h5 class="text-white m-0">Storage</h5>
<div>
<span class="fas fa-pen text-success mr-2" @click="setTab('storage-calculator')"></span>
<span class="fas fa-trash-alt text-danger" @click="deleteStorage()"></span>
</div>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Server Name</span>
<span class="ml-2">{{ cart.storage.serverName }}</span>
</div>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Specification</span>
<span class="ml-2">{{ cart.storage.specification.name }}</span>
</div>
<span>${{ cart.storage.specification.value }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Components</span>
</div>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">vCPU</span>
<span class="ml-2">{{ cart.storage.cpu.qty }} GHz</span>
</div>
<span>${{ cart.storage.cpu.value * cart.storage.cpu.qty }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">vRAM</span>
<span class="ml-2">{{ cart.storage.ram.qty }} Gb</span>
</div>
<span>${{ cart.storage.ram.value * cart.storage.ram.qty }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Capacity</span>
<span class="ml-2">{{ cart.storage.capacity.qty }}</span>
</div>
<span>${{ cart.storage.capacity.value * cart.storage.capacity.qty }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Server Qty</span>
<span class="ml-2">{{ cart.storage.server.qty }}</span>
</div>
<span>${{ cart.storage.server.value * cart.storage.server.qty }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Storage Type</span>
<span class="ml-2">{{ cart.storage.storageType.name }}</span>
</div>
<span>${{ cart.storage.storageType.value }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">OS</span>
<span class="ml-2">{{ cart.storage.os.name }}</span>
</div>
<span>${{ cart.storage.os.value }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Database</span>
<span class="ml-2">{{ cart.storage.database.name }}</span>
</div>
<span>${{ cart.storage.database.value }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Firewall</span>
<span class="ml-2">{{ cart.storage.firewall.name }}</span>
</div>
<span>${{ cart.storage.firewall.value }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Estimate Cost</span>
</div>
<span>${{ cart.storage.totalCost }}</span>
</div>
</div>
<div v-if="cart.service && cart.service.totalCost">
<div class="bg-secondary d-flex justify-content-between p-2">
<h5 class="text-white m-0">Service</h5>
<div>
<span class="fas fa-pen text-success mr-2" @click="setTab('service-calculator')"></span>
<span class="fas fa-trash-alt text-danger" @click="deleteService"></span>
</div>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Sub-service</span>
<span class="ml-2">{{ cart.service.service.name }}</span>
</div>
<span>${{ cart.service.service.value }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Package-type</span>
<span class="ml-2">{{ cart.service.package.name }}</span>
</div>
<span >${{ cart.service.package.value }}</span>
</div>
<div class="d-flex justify-content-between px-2">
<div>
<span class="font-weight-bold">Estimate Cost</span>
</div>
<span>${{ cart.service.totalCost }}</span>
</div>
</div>
<div v-if="cart.deploy && cart.deploy.totalCost">
<div class="estimation-category__title">
<h5 class="m-0 font-size-18 txt-secondary">Cloud Safe</h5>
<div>
<a href="" @click.prevent="setTab('deploy-cloud')"><span class="fas fa-pen text-success font-size-15 mr-2"></span></a>
<a href="" @click.prevent="deleteDeploy()"><span class="fas fa-trash-alt text-danger font-size-15"></span></a>
</div>
</div>
<div class="estimation-category__item">
<div class="font-size-14 txt-primary">
<span class="txt-bold">CPU: </span>
<span class="">{{ cart.deploy.cpuDeploy.name }}</span>
</div>
<span class="font-size-14 txt-secondary">${{ cart.deploy.cpuDeploy.value }}</span>
</div>
<div class="estimation-category__item">
<div class="font-size-14 txt-primary">
<span class="txt-bold">RAM: </span>
<span class="">{{ cart.deploy.ramDeploy.name }}</span>
</div>
<span class="font-size-14 txt-secondary">${{ cart.deploy.ramDeploy.value }}</span>
</div>
<div class="estimation-category__item">
<div class="font-size-14 txt-primary">
<span class="txt-bold">Persistant Volume: </span>
<span class="">{{ cart.deploy.persistant.name }}</span>
</div>
<span class="font-size-14 txt-secondary">${{ cart.deploy.persistant.value }}</span>
</div>
<div class="estimation-category__item">
<div class="font-size-14 txt-primary">
<span class="txt-bold">Storage Type: </span>
<span class="">{{ cart.deploy.workerQty.name }}</span>
</div>
<span class="font-size-14 txt-secondary">${{ cart.deploy.workerQty.value }}</span>
</div>
<div class="estimation-category__item">
<div class="border-cost">
<div class="txt-primary">
<span class="txt-bold font-size-16">Estimate Cost</span>
</div>
<span class="font-size-16 txt-secondary">${{ cart.deploy.totalCost }}</span>
</div>
</div>
</div>
<table class="table table-borderless">
<tbody>
<tr>
<td>
<p>TOTAL</p>
</td>
<td class="text-right">
<p>${{ cart.total }}</p>
</td>
</tr>
</tbody>
</table>
</div>
</transition>
</div>
</div>
</template>
<script>
export default {
props: {
setTab: {type: Function},
},
data: () => ({
isDropped: false
}),
computed: {
cart () {
this.isDropped = !this.isDropped;
return this.$store.getters.getCart;
}
},
methods: {
deleteStorage() {
this.$store.commit('deleteStorage');
},
deleteService() {
this.$store.commit('deleteService');
},
deleteDeploy() {
this.$store.commit('deleteDeploy');
}
},
};
</script>
CSS
.slide-enter, .slide-leave-to{
transform: scaleY(0);
}
.estimation-category{
transform-origin: top;
transition: transform .4s ease-in-out;
overflow: hidden;
}