feat: migrate List component

This commit is contained in:
chenjiahan 2020-07-26 13:18:25 +08:00
parent 7fda2659f5
commit 01c7409e6e
7 changed files with 43 additions and 35 deletions

View File

@ -8,6 +8,7 @@
- Popup: `v-model` 重命名为 `v-model:show` - Popup: `v-model` 重命名为 `v-model:show`
- ShareSheet: `v-model` 重命名为 `v-model:show` - ShareSheet: `v-model` 重命名为 `v-model:show`
- ActionSheet: `v-model` 重命名为 `v-model:show` - ActionSheet: `v-model` 重命名为 `v-model:show`
- List: `v-model` 重命名为 `v-model:loading``error.sync` 重命名为 `v-model:error`
- Field: v-model 对应的属性 `value` 重命名为 `modelValue`,事件由 `input` 重命名为 `update:modelValue` - Field: v-model 对应的属性 `value` 重命名为 `modelValue`,事件由 `input` 重命名为 `update:modelValue`
- Switch: v-model 对应的属性 `value` 重命名为 `modelValue`,事件由 `input` 重命名为 `update:modelValue` - Switch: v-model 对应的属性 `value` 重命名为 `modelValue`,事件由 `input` 重命名为 `update:modelValue`
- Sidebar: v-model 对应的属性 `activeKey` 重命名为 `modelValue`,事件由 `input` 重命名为 `update:modelValue` - Sidebar: v-model 对应的属性 `activeKey` 重命名为 `modelValue`,事件由 `input` 重命名为 `update:modelValue`

View File

@ -39,4 +39,5 @@ module.exports = [
'field', 'field',
'tabbar', 'tabbar',
'tabbar-item', 'tabbar-item',
'list',
]; ];

View File

@ -19,7 +19,7 @@ Vue.use(List);
```html ```html
<van-list <van-list
v-model="loading" v-model:loading="loading"
:finished="finished" :finished="finished"
finished-text="Finished" finished-text="Finished"
@load="onLoad" @load="onLoad"
@ -58,8 +58,8 @@ export default {
```html ```html
<van-list <van-list
v-model="loading" v-model:loading="loading"
:error.sync="error" v-model:error="error"
error-text="Request failed. Click to reload" error-text="Request failed. Click to reload"
@load="onLoad" @load="onLoad"
> >
@ -89,9 +89,9 @@ export default {
### PullRefresh ### PullRefresh
```html ```html
<van-pull-refresh v-model="refreshing" @refresh="onRefresh"> <van-pull-refresh v-model:loading="refreshing" @refresh="onRefresh">
<van-list <van-list
v-model="loading" v-model:loading="loading"
:finished="finished" :finished="finished"
finished-text="Finished" finished-text="Finished"
@load="onLoad" @load="onLoad"
@ -144,7 +144,7 @@ export default {
| Attribute | Description | Type | Default | | Attribute | Description | Type | Default |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| v-model | Whether to show loading infothe `load` event will not be triggered when loading | _boolean_ | `false` | | v-model:loading | Whether to show loading infothe `load` event will not be triggered when loading | _boolean_ | `false` |
| finished | Whether loading is finishedthe `load` event will not be triggered when finished | _boolean_ | `false` | | finished | Whether loading is finishedthe `load` event will not be triggered when finished | _boolean_ | `false` |
| error | Whether loading is errorthe `load` event will be triggered only when error text clicked, the `sync` modifier is needed | _boolean_ | `false` | | error | Whether loading is errorthe `load` event will be triggered only when error text clicked, the `sync` modifier is needed | _boolean_ | `false` |
| offset | The load event will be triggered when the distance between the scrollbar and the bottom is less than offset | _number \| string_ | `300` | | offset | The load event will be triggered when the distance between the scrollbar and the bottom is less than offset | _number \| string_ | `300` |

View File

@ -21,7 +21,7 @@ List 组件通过`loading`和`finished`两个变量控制加载状态,当组
```html ```html
<van-list <van-list
v-model="loading" v-model:loading="loading"
:finished="finished" :finished="finished"
finished-text="没有更多了" finished-text="没有更多了"
@load="onLoad" @load="onLoad"
@ -67,8 +67,8 @@ export default {
```html ```html
<van-list <van-list
v-model="loading" v-model:loading="loading"
:error.sync="error" v-model:error="error"
error-text="请求失败,点击重新加载" error-text="请求失败,点击重新加载"
@load="onLoad" @load="onLoad"
> >
@ -100,9 +100,9 @@ export default {
List 组件可以与 [PullRefresh](#/zh-CN/pull-refresh) 组件结合使用,实现下拉刷新的效果 List 组件可以与 [PullRefresh](#/zh-CN/pull-refresh) 组件结合使用,实现下拉刷新的效果
```html ```html
<van-pull-refresh v-model="refreshing" @refresh="onRefresh"> <van-pull-refresh v-model:loading="refreshing" @refresh="onRefresh">
<van-list <van-list
v-model="loading" v-model:loading="loading"
:finished="finished" :finished="finished"
finished-text="没有更多了" finished-text="没有更多了"
@load="onLoad" @load="onLoad"
@ -159,7 +159,7 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| v-model | 是否处于加载状态,加载过程中不触发`load`事件 | _boolean_ | `false` | | v-model:loading | 是否处于加载状态,加载过程中不触发`load`事件 | _boolean_ | `false` |
| finished | 是否已加载完成,加载完成后不再触发`load`事件 | _boolean_ | `false` | | finished | 是否已加载完成,加载完成后不再触发`load`事件 | _boolean_ | `false` |
| error | 是否加载失败,加载失败后点击错误提示可以重新<br>触发`load`事件,必须使用`sync`修饰符 | _boolean_ | `false` | | error | 是否加载失败,加载失败后点击错误提示可以重新<br>触发`load`事件,必须使用`sync`修饰符 | _boolean_ | `false` |
| offset | 滚动条与底部距离小于 offset 时触发`load`事件 | _number \| string_ | `300` | | offset | 滚动条与底部距离小于 offset 时触发`load`事件 | _number \| string_ | `300` |

View File

@ -3,7 +3,7 @@
<van-tabs> <van-tabs>
<van-tab :title="t('basicUsage')"> <van-tab :title="t('basicUsage')">
<van-list <van-list
v-model="list[0].loading" v-model:loading="list[0].loading"
:finished="list[0].finished" :finished="list[0].finished"
:finished-text="t('finishedText')" :finished-text="t('finishedText')"
@load="onLoad(0)" @load="onLoad(0)"
@ -14,9 +14,9 @@
<van-tab :title="t('errorInfo')"> <van-tab :title="t('errorInfo')">
<van-list <van-list
v-model="list[1].loading" v-model:loading="list[1].loading"
v-model:error="list[1].error"
:finished="list[1].finished" :finished="list[1].finished"
:error.sync="list[1].error"
:error-text="t('errorText')" :error-text="t('errorText')"
@load="onLoad(1)" @load="onLoad(1)"
> >
@ -25,9 +25,12 @@
</van-tab> </van-tab>
<van-tab :title="t('pullRefresh')"> <van-tab :title="t('pullRefresh')">
<van-pull-refresh v-model="list[2].refreshing" @refresh="onRefresh(2)"> <van-pull-refresh
v-model:loading="list[2].refreshing"
@refresh="onRefresh(2)"
>
<van-list <van-list
v-model="list[2].loading" v-model:loading="list[2].loading"
:finished="list[2].finished" :finished="list[2].finished"
:finished-text="t('finishedText')" :finished-text="t('finishedText')"
@load="onLoad(2)" @load="onLoad(2)"

View File

@ -22,10 +22,6 @@ export default createComponent({
}), }),
], ],
model: {
prop: 'loading',
},
props: { props: {
error: Boolean, error: Boolean,
loading: Boolean, loading: Boolean,
@ -47,6 +43,8 @@ export default createComponent({
}, },
}, },
emits: ['load', 'update:error', 'update:loading'],
data() { data() {
return { return {
// use sync innerLoading state to avoid repeated loading in some edge cases // use sync innerLoading state to avoid repeated loading in some edge cases
@ -107,7 +105,7 @@ export default createComponent({
if (isReachEdge) { if (isReachEdge) {
this.innerLoading = true; this.innerLoading = true;
this.$emit('input', true); this.$emit('update:loading', true);
this.$emit('load'); this.$emit('load');
} }
}); });
@ -122,7 +120,9 @@ export default createComponent({
if (this.innerLoading && !this.finished) { if (this.innerLoading && !this.finished) {
return ( return (
<div class={bem('loading')} key="loading"> <div class={bem('loading')} key="loading">
{this.slots('loading') || ( {this.$slots.loading ? (
this.$slots.loading()
) : (
<Loading size="16">{this.loadingText || t('loading')}</Loading> <Loading size="16">{this.loadingText || t('loading')}</Loading>
)} )}
</div> </div>
@ -132,7 +132,9 @@ export default createComponent({
genFinishedText() { genFinishedText() {
if (this.finished) { if (this.finished) {
const text = this.slots('finished') || this.finishedText; const text = this.$slots.finished
? this.$slots.finished()
: this.finishedText;
if (text) { if (text) {
return <div class={bem('finished-text')}>{text}</div>; return <div class={bem('finished-text')}>{text}</div>;
@ -142,7 +144,7 @@ export default createComponent({
genErrorText() { genErrorText() {
if (this.error) { if (this.error) {
const text = this.slots('error') || this.errorText; const text = this.$slots.error ? this.$slots.error() : this.errorText;
if (text) { if (text) {
return ( return (
@ -157,14 +159,15 @@ export default createComponent({
render() { render() {
const Placeholder = <div ref="placeholder" class={bem('placeholder')} />; const Placeholder = <div ref="placeholder" class={bem('placeholder')} />;
const Content = this.$slots.default?.();
return ( return (
<div class={bem()} role="feed" aria-busy={this.innerLoading}> <div class={bem()} role="feed" aria-busy={this.innerLoading}>
{this.direction === 'down' ? this.slots() : Placeholder} {this.direction === 'down' ? Content : Placeholder}
{this.genLoading()} {this.genLoading()}
{this.genFinishedText()} {this.genFinishedText()}
{this.genErrorText()} {this.genErrorText()}
{this.direction === 'up' ? this.slots() : Placeholder} {this.direction === 'up' ? Content : Placeholder}
</div> </div>
); );
}, },

View File

@ -249,10 +249,10 @@ module.exports = {
// path: 'lazyload', // path: 'lazyload',
// title: 'Lazyload 懒加载', // title: 'Lazyload 懒加载',
// }, // },
// { {
// path: 'list', path: 'list',
// title: 'List 列表', title: 'List 列表',
// }, },
{ {
path: 'notice-bar', path: 'notice-bar',
title: 'NoticeBar 通知栏', title: 'NoticeBar 通知栏',
@ -583,10 +583,10 @@ module.exports = {
// path: 'lazyload', // path: 'lazyload',
// title: 'Lazyload', // title: 'Lazyload',
// }, // },
// { {
// path: 'list', path: 'list',
// title: 'List', title: 'List',
// }, },
{ {
path: 'notice-bar', path: 'notice-bar',
title: 'NoticeBar', title: 'NoticeBar',