Skip to content

ActionSheet

Basic use

  • Pass title (set the title), cancelText (the text of the cancel button, display the button if it is not empty), description (description information above the option).
  • Set the menu to be displayed through actions. The value is an array, and the elements are objects. The object must provide at least the name attribute. In addition, the optional subname (description), disabled (whether it is disabled), loading (loading animation), color (font color), fontSize (font size).
  • Control the opening of the component by calling open() through ref.
vue
<template>
	<view>
		<wu-action-sheet 
		ref="actionSheet"
		:actions="list" 
		title="title"
		@select="select"
		@close="close">
		</wu-action-sheet>
		<button @click="open">Open ActionSheet</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
					name: 'Option one',
					subname: "Option one description",
					color: '#ffaa7f',
					fontSize: '20'
				}, {
					name: 'Option 2 is disabled',
					disabled: true
				}, {
					name: 'Enable load loading', //Text is not displayed after turning it on
					loading: true
				}]
			}
		},
		methods: {
			open() {
				this.$refs.actionSheet.open();
			},
			select(e){
				console.log('Check this item:',e);
			},
			close(){
				console.log('close');
			}
		}
	}
</script>
<template>
	<view>
		<wu-action-sheet 
		ref="actionSheet"
		:actions="list" 
		title="title"
		@select="select"
		@close="close">
		</wu-action-sheet>
		<button @click="open">Open ActionSheet</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
					name: 'Option one',
					subname: "Option one description",
					color: '#ffaa7f',
					fontSize: '20'
				}, {
					name: 'Option 2 is disabled',
					disabled: true
				}, {
					name: 'Enable load loading', //Text is not displayed after turning it on
					loading: true
				}]
			}
		},
		methods: {
			open() {
				this.$refs.actionSheet.open();
			},
			select(e){
				console.log('Check this item:',e);
			},
			close(){
				console.log('close');
			}
		}
	}
</script>

Configure click mask to close and close the pop-up window when clicking a menu item

  • Use the closeOnClickAction parameter to configure whether to close the pop-up window when a menu item is clicked. Setting it to false does not affect the return of the select event. The default is true.
  • Use the closeOnClickOverlay parameter to configure whether the click mask is allowed to be closed. The default is true.
vue
<template>
	<view>
		<wu-action-sheet 
		ref="actionSheet" 
		:actions="list" 
		title="title" 
		:closeOnClickOverlay="false" 
		:closeOnClickAction="false" 
		@select="select" 
		@close="close">
		</wu-action-sheet>
		<button @click="open">Open ActionSheet</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
					name: 'Option one'
				}, {
					name: 'Option two'
				}]
			}
		},
		methods: {
			open() {
				this.$refs.actionSheet.open();
			},
			select(e) {
				console.log('Check this item:', e);
			},
			close() {
				console.log('close');
			}
		}
	}
</script>
<template>
	<view>
		<wu-action-sheet 
		ref="actionSheet" 
		:actions="list" 
		title="title" 
		:closeOnClickOverlay="false" 
		:closeOnClickAction="false" 
		@select="select" 
		@close="close">
		</wu-action-sheet>
		<button @click="open">Open ActionSheet</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
					name: 'Option one'
				}, {
					name: 'Option two'
				}]
			}
		},
		methods: {
			open() {
				this.$refs.actionSheet.open();
			},
			select(e) {
				console.log('Check this item:', e);
			},
			close() {
				console.log('close');
			}
		}
	}
</script>

Open capabilities

For all open capabilities, please refer to the button provided by uni Open capabilities

vue
<template>
	<view>
		<wu-action-sheet 
		ref="actionSheet" 
		:actions="list" 
		title="Open capabilities" 
		@select="select" 
		@close="close">
		</wu-action-sheet>
		<button @click="open">Open ActionSheet</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
					name: 'Open capabilities-Share',
					openType: 'share'
				},{
					name: 'Open ability-obtain user information',
					openType: 'getUserInfo'
				},{
					name: 'Open capabilities-Customer service session',
					openType: 'contact'
				},{
					name: 'Open capabilities-other'
				}]
			}
		},
		methods: {
			open() {
				this.$refs.actionSheet.open();
			},
			select(e) {
				console.log('Check this item:', e);
				if(e.name == 'Open capabilities-other') {
					uni.showModal({
						content: 'Refer to the button opening capabilities provided by uni',
						showCancel: false
					})
				}
			},
			close() {
				console.log('close');
			}
		}
	}
</script>
<template>
	<view>
		<wu-action-sheet 
		ref="actionSheet" 
		:actions="list" 
		title="Open capabilities" 
		@select="select" 
		@close="close">
		</wu-action-sheet>
		<button @click="open">Open ActionSheet</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [{
					name: 'Open capabilities-Share',
					openType: 'share'
				},{
					name: 'Open ability-obtain user information',
					openType: 'getUserInfo'
				},{
					name: 'Open capabilities-Customer service session',
					openType: 'contact'
				},{
					name: 'Open capabilities-other'
				}]
			}
		},
		methods: {
			open() {
				this.$refs.actionSheet.open();
			},
			select(e) {
				console.log('Check this item:', e);
				if(e.name == 'Open capabilities-other') {
					uni.showModal({
						content: 'Refer to the button opening capabilities provided by uni',
						showCancel: false
					})
				}
			},
			close() {
				console.log('close');
			}
		}
	}
</script>

API

ActionSheet Props

ParametersDescriptionTypeDefault valueOptional value
titleSet titleString--
descriptionDescription information above the optionString--
actionsThe text array of the button, see the document example aboveArray<Object>[ ]-
cancelTextThe text of the cancel button, the button is displayed when it is not emptyString--
safeAreaInsetBottomWhether to enable bottom safe area adaptationBooleanfalsetrue / false
closeOnClickOverlayWhether the click mask allows closing the componentBoolean--
closeOnClickActionWhether to close the component when a menu item is clickedBooleantruetrue / false
roundrounded corner value, no rounded corner by defaultString / Number0-
langSpecify the language for returning user information, zh_CN Simplified Chinese, zh_TW Traditional Chinese, en EnglishStringenen / zh_CN / zh_TW
sessionFromSession source, valid when open-type="contact". Only valid for WeChat appletString--
sendMessageTitleThe title of the message card in the session, valid when openType="contact"String--
sendMessagePathClick to jump to the applet path of the message card in the session, valid when openType="contact"String--
sendMessageImgIn-session message card image, valid when openType="contact"String--
showMessageCardWhether to display the in-session message card. Set this parameter to true. When the user enters the customer service session, the "Possible mini program to be sent" prompt will be displayed in the lower right corner. The user can quickly send the mini program message after clicking it, openType="contact Valid when "Booleanfalsetrue / false
appParameterThe parameter passed to APP when opening APP, valid when openType=launchAppString--

ActionSheet Actions Props

ParametersDescriptionTypeDefault valueOptional value
openTypeHow to open the appletString''-
disabledWhether the menu is disabledBooleanfalsetrue / false
loadingWhether the menu is loadingBooleanfalsetrue / false
nameThe title of this menuString''-
subnameDescription of this menuString''-
fontSizeThe size of the menu name text, unit px(rpx)String16px-
colorThe color of the menu name textString#303133-

ActionSheet Methods

Method nameDescription
openPop-up operation menu component
closeClose the operation menu component

ActionSheet Events

Event nameDescriptionCallback parameters
selectTriggered when an ActionSheet list item is clicked-
closeFired when the cancel button is clicked. Clicking on the mask to trigger this event requires setting :closeOnClickOverlay="true"-
getuserinfoWhen the user clicks this button, the obtained user information will be returned. The detail data of the callback is consistent with that returned by wx.getUserInfo, which is valid when openType="getUserInfo"detail
contactCustomer service message callback, valid when openType="contact"-
getphonenumberCallback to get the user's mobile phone number, valid when openType="getPhoneNumber"-
errorWhen using open capabilities, the callback when an error occurs, valid when openType="error"-
launchappCallback for successful opening of APP, valid when openType="launchApp"-
opensettingCalled after opening the authorization setting page, valid when openType="openSetting"-