mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-26 19:36:36 +08:00
docs(SwipeCell): use composition api
This commit is contained in:
parent
d1f637afc7
commit
75f8e36923
@ -71,9 +71,11 @@ app.use(SwipeCell);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { Dialog } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
setup() {
|
||||||
beforeClose({ position, instance }) {
|
const beforeClose = ({ position }) => {
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 'left':
|
case 'left':
|
||||||
case 'cell':
|
case 'cell':
|
||||||
@ -81,14 +83,14 @@ export default {
|
|||||||
return true;
|
return true;
|
||||||
case 'right':
|
case 'right':
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.$dialog
|
Dialog.confirm({
|
||||||
.confirm({
|
title: 'Are you sure to delete?',
|
||||||
message: 'Are you sure to delete?',
|
}).then(resolve);
|
||||||
})
|
|
||||||
.then(resolve);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return { beforeClose };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -81,10 +81,12 @@ app.use(SwipeCell);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { Dialog } from 'vant';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
setup() {
|
||||||
// position 为关闭时点击的位置
|
// position 为关闭时点击的位置
|
||||||
beforeClose({ position }) {
|
const beforeClose = ({ position }) => {
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 'left':
|
case 'left':
|
||||||
case 'cell':
|
case 'cell':
|
||||||
@ -92,14 +94,14 @@ export default {
|
|||||||
return true;
|
return true;
|
||||||
case 'right':
|
case 'right':
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.$dialog
|
Dialog.confirm({
|
||||||
.confirm({
|
title: '确定删除吗?',
|
||||||
message: '确定删除吗?',
|
}).then(resolve);
|
||||||
})
|
|
||||||
.then(resolve);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return { beforeClose };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -45,9 +45,11 @@
|
|||||||
</demo-block>
|
</demo-block>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
export default {
|
import { useTranslate } from '@demo/use-translate';
|
||||||
i18n: {
|
import Dialog from '../../dialog';
|
||||||
|
|
||||||
|
const i18n = {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
select: '选择',
|
select: '选择',
|
||||||
delete: '删除',
|
delete: '删除',
|
||||||
@ -68,16 +70,12 @@ export default {
|
|||||||
beforeClose: 'Before Close',
|
beforeClose: 'Before Close',
|
||||||
customContent: 'Custom Content',
|
customContent: 'Custom Content',
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
imageURL: 'https://img.yzcdn.cn/vant/ipad.jpeg',
|
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
export default {
|
||||||
beforeClose({ position }) {
|
setup() {
|
||||||
|
const t = useTranslate(i18n);
|
||||||
|
const beforeClose = ({ position }: { position: string }) => {
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 'left':
|
case 'left':
|
||||||
case 'cell':
|
case 'cell':
|
||||||
@ -85,14 +83,18 @@ export default {
|
|||||||
return true;
|
return true;
|
||||||
case 'right':
|
case 'right':
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.$dialog
|
Dialog.confirm({
|
||||||
.confirm({
|
title: t('confirm'),
|
||||||
message: this.t('confirm'),
|
}).then(resolve);
|
||||||
})
|
|
||||||
.then(resolve);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
t,
|
||||||
|
imageURL: 'https://img.yzcdn.cn/vant/ipad.jpeg',
|
||||||
|
beforeClose,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user