写出代码:用vue使用van-swipe-cell能实现滑动删除van card的html文件
时间: 2024-03-07 17:49:05 浏览: 162
vue-swipe-actions:iOS风格的滑动动作
以下是一个示例代码,使用Vue和Vanilla Swipe Cell实现滑动删除Van Card:
```html
<template>
<div>
<van-card
v-for="(item, index) in items"
:key="index"
>
<van-swipe-cell
:left-width="60"
:right-width="60"
@click="deleteItem(index)"
>
<div slot="left" class="van-swipe-cell__left">
<van-icon name="delete" />
</div>
<div class="van-card__content">
<p>{{ item.title }}</p>
<p>{{ item.description }}</p>
</div>
<div slot="right" class="van-swipe-cell__right">
<van-icon name="delete" />
</div>
</van-swipe-cell>
</van-card>
</div>
</template>
<script>
import { SwipeCell, Icon, Card } from 'vant';
export default {
name: 'SwipeDelete',
components: {
SwipeCell,
Icon,
Card
},
data() {
return {
items: [
{
title: 'Item 1',
description: 'This is the first item'
},
{
title: 'Item 2',
description: 'This is the second item'
},
{
title: 'Item 3',
description: 'This is the third item'
}
]
}
},
methods: {
deleteItem(index) {
this.items.splice(index, 1);
}
}
}
</script>
<style>
/*自定义样式*/
</style>
```
上述代码中,我们使用了Vanilla Swipe Cell组件来实现滑动删除效果,并将其套在Van Card组件中。在Van Swipe Cell组件中,我们使用了左右两个插槽来分别放置删除按钮。在删除按钮被点击时,我们调用deleteItem方法从items数组中删除该项。
阅读全文