国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

Vant2 SwipeCell 滑動(dòng)單元格

2025-08-28 14:26 更新

介紹

可以左右滑動(dòng)來展示操作按鈕的單元格組件。

引入

import Vue from 'vue';
import { SwipeCell } from 'vant';

Vue.use(SwipeCell);

代碼演示

基礎(chǔ)用法

SwipeCell 組件提供了 leftright 兩個(gè)插槽,用于定義兩側(cè)滑動(dòng)區(qū)域的內(nèi)容。

<van-swipe-cell>
  <template #left>
    <van-button square type="primary" text="選擇" />
  </template>
  <van-cell :border="false" title="單元格" value="內(nèi)容" />
  <template #right>
    <van-button square type="danger" text="刪除" />
    <van-button square type="primary" text="收藏" />
  </template>
</van-swipe-cell>

自定義內(nèi)容

SwipeCell 可以嵌套任意內(nèi)容,比如嵌套一個(gè)商品卡片。

<van-swipe-cell>
  <van-card
    num="2"
    price="2.00"
    desc="描述信息"
    title="商品標(biāo)題"
    class="goods-card"
    thumb="https://img01.yzcdn.cn/vant/cat.jpeg"
  />
  <template #right>
    <van-button square text="刪除" type="danger" class="delete-button" />
  </template>
</van-swipe-cell>

<style>
  .goods-card {
    margin: 0;
    background-color: @white;
  }

  .delete-button {
    height: 100%;
  }
</style>

異步關(guān)閉

通過傳入 before-close 回調(diào)函數(shù),可以自定義兩側(cè)滑動(dòng)內(nèi)容關(guān)閉時(shí)的行為。

<van-swipe-cell :before-close="beforeClose">
  <template #left>
    <van-button square type="primary" text="選擇" />
  </template>
  <van-cell :border="false" title="單元格" value="內(nèi)容" />
  <template #right>
    <van-button square type="danger" text="刪除" />
  </template>
</van-swipe-cell>
export default {
  methods: {
    // position 為關(guān)閉時(shí)點(diǎn)擊的位置
    // instance 為對(duì)應(yīng)的 SwipeCell 實(shí)例
    beforeClose({ position, instance }) {
      switch (position) {
        case 'left':
        case 'cell':
        case 'outside':
          instance.close();
          break;
        case 'right':
          Dialog.confirm({
            message: '確定刪除嗎?',
          }).then(() => {
            instance.close();
          });
          break;
      }
    },
  },
};

API

Props

參數(shù) 說明 類型 默認(rèn)值
name 標(biāo)識(shí)符,可以在事件參數(shù)中獲取到 number | string -
left-width 指定左側(cè)滑動(dòng)區(qū)域?qū)挾?,單位?code>px number | string auto
right-width 指定右側(cè)滑動(dòng)區(qū)域?qū)挾?,單位?code>px number | string auto
before-close 關(guān)閉前的回調(diào)函數(shù) Function -
disabled 是否禁用滑動(dòng) boolean false
stop-propagation 是否阻止滑動(dòng)事件冒泡 boolean false

Slots

名稱 說明
default 自定義顯示內(nèi)容
left 左側(cè)滑動(dòng)內(nèi)容
right 右側(cè)滑動(dòng)內(nèi)容

Events

事件名 說明 回調(diào)參數(shù)
click 點(diǎn)擊時(shí)觸發(fā) 關(guān)閉時(shí)的點(diǎn)擊位置 (left right cell outside)
open 打開時(shí)觸發(fā) { position: 'left' | 'right' , name: string }
close 關(guān)閉時(shí)觸發(fā) { position: string , name: string }

beforeClose 參數(shù)

beforeClose 的第一個(gè)參數(shù)為對(duì)象,對(duì)象中包含以下屬性:

參數(shù)名 說明 類型
name 標(biāo)識(shí)符 string
position 關(guān)閉時(shí)的點(diǎn)擊位置 (left right cell outside) string
instance SwipeCell 實(shí)例,用于調(diào)用實(shí)例方法 SwipeCell

方法

通過 ref 可以獲取到 SwipeCell 實(shí)例并調(diào)用實(shí)例方法,詳見組件實(shí)例方法

方法名 說明 參數(shù) 返回值
open 打開單元格側(cè)邊欄 position: left \| right -
close 收起單元格側(cè)邊欄 - -

樣式變量

組件提供了下列 Less 變量,可用于自定義樣式,使用方法請(qǐng)參考主題定制

名稱 默認(rèn)值 描述
@switch-cell-padding-top @cell-vertical-padding - 1px -
@switch-cell-padding-bottom @cell-vertical-padding - 1px -
@switch-cell-large-padding-top @cell-large-vertical-padding - 1px -
@switch-cell-large-padding-bottom @cell-large-vertical-padding - 1px -

常見問題

在桌面端無法操作組件?

參見桌面端適配。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)