diff --git a/src/toast/Toast.js b/src/toast/Toast.js
index 950c88464..672529a14 100644
--- a/src/toast/Toast.js
+++ b/src/toast/Toast.js
@@ -6,6 +6,7 @@ import { lockClick } from './lock-click';
import Icon from '../icon';
import Popup from '../popup';
import Loading from '../loading';
+import { watch, onMounted, onUnmounted } from 'vue';
const [createComponent, bem] = createNamespace('toast');
@@ -13,13 +14,13 @@ export default createComponent({
props: {
icon: String,
show: Boolean,
- clear: Function,
+ message: [Number, String],
className: null,
iconPrefix: String,
+ lockScroll: Boolean,
loadingType: String,
forbidClick: Boolean,
closeOnClick: Boolean,
- message: [Number, String],
type: {
type: String,
default: 'text',
@@ -32,72 +33,37 @@ export default createComponent({
type: String,
default: 'van-fade',
},
- lockScroll: {
- type: Boolean,
- default: false,
- },
},
- emits: ['opened', 'closed', 'update:show'],
+ emits: ['update:show'],
- data() {
- return {
- clickable: false,
- };
- },
+ setup(props, { emit }) {
+ let clickable;
- mounted() {
- this.toggleClickable();
- },
-
- unmounted() {
- this.toggleClickable();
- },
-
- watch: {
- show: 'toggleClickable',
- forbidClick: 'toggleClickable',
- },
-
- methods: {
- onClick() {
- if (this.closeOnClick) {
- this.close();
- }
- },
-
- toggleClickable() {
- const clickable = this.show && this.forbidClick;
-
- if (this.clickable !== clickable) {
- this.clickable = clickable;
+ const toggleClickable = () => {
+ const newValue = props.show && props.forbidClick;
+ if (clickable !== newValue) {
+ clickable = newValue;
lockClick(clickable);
}
- },
+ };
- /* istanbul ignore next */
- onAfterEnter() {
- this.$emit('opened');
-
- if (this.onOpened) {
- this.onOpened();
+ const onClick = () => {
+ if (props.closeOnClick) {
+ emit('update:show', false);
}
- },
+ };
- onAfterLeave() {
- this.$emit('closed');
- },
-
- genIcon() {
- const { icon, type, iconPrefix, loadingType } = this;
+ const renderIcon = () => {
+ const { icon, type, iconPrefix, loadingType } = props;
const hasIcon = icon || type === 'success' || type === 'fail';
if (hasIcon) {
return (