vant/src/action-sheet/README.md
2020-11-21 18:47:31 +08:00

4.5 KiB

ActionSheet

Install

import { createApp } from 'vue';
import { ActionSheet } from 'vant';

const app = createApp();
app.use(ActionSheet);

Usage

Basic Usage

Use actions prop to set options of action-sheet.

<van-cell is-link title="Basic Usage" @click="show = true" />
<van-action-sheet v-model:show="show" :actions="actions" @select="onSelect" />
import { Toast } from 'vant';

export default {
  data() {
    return {
      show: false,
      actions: [
        { name: 'Option 1' },
        { name: 'Option 2' },
        { name: 'Option 3' },
      ],
    };
  },
  methods: {
    onSelect(item) {
      this.show = false;
      Toast(item.name);
    },
  },
};

Show Cancel Button

<van-action-sheet
  v-model:show="show"
  :actions="actions"
  cancel-text="Cancel"
  close-on-click-action
  @cancel="onCancel"
/>
import { Toast } from 'vant';

export default {
  data() {
    return {
      show: false,
      actions: [
        { name: 'Option 1' },
        { name: 'Option 2' },
        { name: 'Option 3' },
      ],
    };
  },
  methods: {
    onCancel() {
      Toast('cancel');
    },
  },
};

Show Description

<van-action-sheet
  v-model:show="show"
  :actions="actions"
  cancel-text="Cancel"
  description="Description"
  close-on-click-action
/>
export default {
  data() {
    return {
      show: false,
      actions: [
        { name: 'Option 1' },
        { name: 'Option 2' },
        { name: 'Option 3', subname: 'Description' },
      ],
    };
  },
};

Option Status

<van-action-sheet
  v-model:show="show"
  :actions="actions"
  cancel-text="Cancel"
  close-on-click-action
/>
export default {
  data() {
    return {
      show: false,
      actions: [
        { name: 'Colored Option', color: '#ee0a24' },
        { name: 'Disabled Option', disabled: true },
        { name: 'Loading Option', loading: true },
      ],
    };
  },
};

Custom Panel

<van-action-sheet v-model:show="show" title="Title">
  <div class="content">Content</div>
</van-action-sheet>

<style>
  .content {
    padding: 16px 16px 160px;
  }
</style>

API

Props

Attribute Description Type Default
v-model:show Whether to show ActionSheet boolean false
actions Options Action[] []
title Title string -
cancel-text Text of cancel button string -
description Description above the options string -
closeable v2.10.5 Whether to show close icon boolean true
close-icon Close icon name string cross
duration Transition duration, unit second number | string 0.3
round Whether to show round corner boolean true
overlay Whether to show overlay boolean true
lock-scroll Whether to lock background scroll boolean true
lazy-render Whether to lazy render util appeared boolean true
close-on-popstate v2.5.3 Whether to close when popstate boolean false
close-on-click-action Whether to close when an action is clicked boolean false
close-on-click-overlay Whether to close when overlay is clicked boolean true
safe-area-inset-bottom Whether to enable bottom safe area adaptation boolean true
teleport Return the mount node for ActionSheet string | Element -

Data Structure of Action

Key Description Type
name Title string
subname Subtitle string
color Text color string
className className for the option any
loading Whether to be loading status boolean
disabled Whether to be disabled boolean

Events

Event Description Arguments
select Emitted when an option is clicked action: Action, index: number
cancel Emitted when the cancel button is clicked -
open Emitted when opening ActionSheet -
close Emitted when closing ActionSheet -
opened Emitted when ActionSheet is opened -
closed Emitted when ActionSheet is closed -
click-overlay Emitted when overlay is clicked -

Slots

Name Description
default Custom content
description v2.10.4 Custom description