From e48df13c81ae1a4778670ac4c67cb63d90fb1c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E6=96=87=E5=8D=8E?= <531362022@qq.com> Date: Mon, 21 Sep 2020 14:35:48 +0800 Subject: [PATCH] docs: Update readme [skip ci] --- README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7e8467d..4aea393 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,12 @@ const tpl = graphql.query({ // } // 在模型中使用 +type Response = { + data: typeof tpl.type; +}; + +type Data = Response['data']; + class TestModel extends Model { getUser = $api.action((page: number, size: number = 10) => { return this @@ -104,7 +110,7 @@ class TestModel extends Model { size_Int: size, })) .onSuccess((state, action) => { - state.list = action.response.data; + return action.response.data; }); }); @@ -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 } ```