Skip to content

Commit

Permalink
docs: Update readme [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
fwh1990 committed Sep 21, 2020
1 parent 0242cb9 commit e48df13
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ const tpl = graphql.query({
// }

// 在模型中使用
type Response = {
data: typeof tpl.type;
};

type Data = Response['data'];

class TestModel extends Model<Data> {
getUser = $api.action((page: number, size: number = 10) => {
return this
Expand All @@ -104,7 +110,7 @@ class TestModel extends Model<Data> {
size_Int: size,
}))
.onSuccess((state, action) => {
state.list = action.response.data;
return action.response.data;
});
});

Expand Down Expand Up @@ -213,10 +219,20 @@ const tpl = graphql.query({
您可以通过判断来确定哪个字段存在

```typescript
if (data.kind === 'User') {
// data.name
} else if (data.kind === 'Admin') {
// data.name1
if (getUser.kind === 'User') {
// getUser.name
// getUser.age
} else if (getUser.kind === 'Admin') {
// getUser.name1
// getUser.age1
}

if ('age' in getUser) {
// getUser.name
// getUser.age
} else if ('age1' in getUser) {
// getUser.name1
// getUser.age1
}
```

Expand Down

0 comments on commit e48df13

Please sign in to comment.