mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(NoticeBar): add reset method (#8917)
This commit is contained in:
parent
dc8f190733
commit
4f0ca629b2
@ -514,11 +514,11 @@ export default {
|
|||||||
|
|
||||||
### validate-trigger
|
### validate-trigger
|
||||||
|
|
||||||
| Value | Description |
|
| Value | Description |
|
||||||
| -------- | --------------------------------------------------------------- |
|
| -------- | ---------------------------------------------------------------- |
|
||||||
| onSubmit | Trigger validation after submiting form |
|
| onSubmit | Trigger validation after submitting form |
|
||||||
| onBlur | Trigger validation after submiting form or bluring input |
|
| onBlur | Trigger validation after submitting form or blurring input |
|
||||||
| onChange | Trigger validation after submiting form or changing input value |
|
| onChange | Trigger validation after submitting form or changing input value |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
useEventListener,
|
useEventListener,
|
||||||
onMountedOrActivated,
|
onMountedOrActivated,
|
||||||
} from '@vant/use';
|
} from '@vant/use';
|
||||||
|
import { useExpose } from '../composables/use-expose';
|
||||||
import { onPopupReopen } from '../composables/on-popup-reopen';
|
import { onPopupReopen } from '../composables/on-popup-reopen';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
@ -140,17 +141,13 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
|
const { delay, speed, scrollable } = props;
|
||||||
|
const ms = isDef(delay) ? +delay * 1000 : 0;
|
||||||
|
|
||||||
wrapWidth = 0;
|
wrapWidth = 0;
|
||||||
contentWidth = 0;
|
contentWidth = 0;
|
||||||
state.offset = 0;
|
state.offset = 0;
|
||||||
state.duration = 0;
|
state.duration = 0;
|
||||||
};
|
|
||||||
|
|
||||||
const start = () => {
|
|
||||||
const { delay, speed, scrollable } = props;
|
|
||||||
const ms = isDef(delay) ? +delay * 1000 : 0;
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
clearTimeout(startTimer);
|
clearTimeout(startTimer);
|
||||||
startTimer = setTimeout(() => {
|
startTimer = setTimeout(() => {
|
||||||
@ -172,14 +169,15 @@ export default defineComponent({
|
|||||||
}, ms);
|
}, ms);
|
||||||
};
|
};
|
||||||
|
|
||||||
onPopupReopen(start);
|
onPopupReopen(reset);
|
||||||
onMountedOrActivated(start);
|
onMountedOrActivated(reset);
|
||||||
|
|
||||||
// fix cache issues with forwards and back history in safari
|
// fix cache issues with forwards and back history in safari
|
||||||
// see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/
|
// see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/
|
||||||
useEventListener('pageshow', start);
|
useEventListener('pageshow', reset);
|
||||||
|
useExpose({ reset });
|
||||||
|
|
||||||
watch(() => [props.text, props.scrollable], start);
|
watch(() => [props.text, props.scrollable], reset);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const { color, wrapable, background } = props;
|
const { color, wrapable, background } = props;
|
||||||
|
@ -107,6 +107,14 @@ app.use(NoticeBar);
|
|||||||
| close | Emitted when NoticeBar is closed | _event: MouseEvent_ |
|
| close | Emitted when NoticeBar is closed | _event: MouseEvent_ |
|
||||||
| replay | Emitted when NoticeBar is replayed | - |
|
| replay | Emitted when NoticeBar is replayed | - |
|
||||||
|
|
||||||
|
### Methods
|
||||||
|
|
||||||
|
Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get NoticeBar instance and call instance methods.
|
||||||
|
|
||||||
|
| Name | Description | Attribute | Return value |
|
||||||
|
| -------------- | --------------- | --------- | ------------ |
|
||||||
|
| reset `v3.1.1` | Reset NoticeBar | - | - |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
| Name | Description |
|
| Name | Description |
|
||||||
|
@ -128,6 +128,14 @@ app.use(NoticeBar);
|
|||||||
| close | 关闭通知栏时触发 | _event: MouseEvent_ |
|
| close | 关闭通知栏时触发 | _event: MouseEvent_ |
|
||||||
| replay | 每当滚动栏重新开始滚动时触发 | - |
|
| replay | 每当滚动栏重新开始滚动时触发 | - |
|
||||||
|
|
||||||
|
### 方法
|
||||||
|
|
||||||
|
通过 ref 可以获取到 NoticeBar 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。
|
||||||
|
|
||||||
|
| 方法名 | 说明 | 参数 | 返回值 |
|
||||||
|
| -------------- | -------------------- | ---- | ------ |
|
||||||
|
| reset `v3.1.1` | 重置通知栏到初始状态 | - | - |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
| 名称 | 内容 |
|
| 名称 | 内容 |
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { NoticeBar } from '..';
|
import { NoticeBar } from '..';
|
||||||
import { mount, later } from '../../../test';
|
import { mount, later } from '../../../test';
|
||||||
|
import type { ComponentInstance } from '../../utils';
|
||||||
|
|
||||||
test('should emit close event when close icon is clicked', () => {
|
test('should emit close event when close icon is clicked', () => {
|
||||||
const wrapper = mount(NoticeBar, {
|
const wrapper = mount(NoticeBar, {
|
||||||
@ -91,3 +92,13 @@ test('should not start scrolling when content width > wrap width ', async () =>
|
|||||||
|
|
||||||
expect(wrapper.html()).toMatchSnapshot();
|
expect(wrapper.html()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should expose reset methods', async () => {
|
||||||
|
const wrapper = mount(NoticeBar, {
|
||||||
|
props: {
|
||||||
|
text: 'foo',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect((wrapper.vm as ComponentInstance).reset).toBeTruthy();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user