根據官方教程,在wxml里鍵入
<van-swipe-cell id="swipe-cell" right-width="{{ 65 }}" left-width="{{ 65 }}" async-close bind:close="onClose">
<view slot="left">選擇</view>
<van-cell-group>
<van-cell title="單元格" value="內容" />
</van-cell-group>
<view slot="right">刪除</view>
</van-swipe-cell>
,在.js里鍵入
Page({
onClose(event) {
const { position, instance } = event.detail;
switch (position) {
case 'left':
case 'cell':
instance.close();
break;
case 'right':
Dialog.confirm({
message: '確定刪除嗎?'
}).then(() => {
instance.close();
});
break;
}
}
});
是得不到官方的效果如下的:
你會發現右邊的刪除是沒有樣式的,
因此,需要在wxss里添加上如下樣式:
.van-swipe-cell__left,
.van-swipe-cell__right {
display: inline-block;
width: 65px;
height: 44px;
font-size: 15px;
line-height: 44px;
color: #fff;
text-align: center;
background-color: #f44;
}