Vant SwipeCell 滑动单元格分析
发布时间:2023-04-20 12:36:44 所属栏目:教程 来源:
导读:Vant SwipeCell 滑动单元格是提供可以在两侧加入内容的组件。
引入
import Vue from 'vue';
import { SwipeCell } from 'vant';
Vue.use(SwipeCell);
基础用法
SwipeCell组件提供了left和
引入
import Vue from 'vue';
import { SwipeCell } from 'vant';
Vue.use(SwipeCell);
基础用法
SwipeCell组件提供了left和
Vant SwipeCell 滑动单元格是提供可以在两侧加入内容的组件。 引入 import Vue from 'vue'; import { SwipeCell } from 'vant'; Vue.use(SwipeCell); 基础用法 SwipeCell组件提供了left和right两个插槽,用于定义两侧滑动区域的内容 <van-swipe-cell> <template slot="left"> <van-button square type="primary" text="选择" /> </template> <van-cell :border="false" title="单元格" value="内容" /> <template slot="right"> <van-button square type="danger" text="删除" /> <van-button square type="primary" text="收藏"/> </template> </van-swipe-cell> 自定义内容 SwipeCell内容可以嵌套任意内容,比如嵌套一个商品卡片 <van-swipe-cell> <van-card num="2" price="2.00" desc="描述信息" title="商品标题" class="goods-card" thumb="https://img.yzcdn.cn/vant/cat.jpeg" /> <van-button slot="right" square text="删除" type="danger" class="delete-button" /> </van-swipe-cell> <style> .goods-card { margin: 0; background-color: @white; } .delete-button { height: 100%; } </style> 异步关闭 通过传入before-close回调函数,可以自定义两侧滑动内容关闭时的行为 <van-swipe-cell :before-close="beforeClose"> <template slot="left"> <van-button square type="primary" text="选择" /> </template> <van-cell :border="false" title="单元格" value="内容" /> <template slot="right"> <van-button square type="danger" text="删除" /> </template> </van-swipe-cell> export default { methods: { // position 为关闭时点击的位置 // instance 为对应的 SwipeCell 实例 beforeClose({ position, instance }) { switch (position) { case 'left': case 'cell': case 'outside': instance.close(); break; case 'right': Dialog.confirm({ message: '确定删除吗?' }).then(() => { instance.close(); }); break; } } } } (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |