From 733c9a2acf830e663ad7431e85b395f954cbdc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=90=AA?= <572962673@qq.com> Date: Wed, 16 May 2018 10:27:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9pullrefresh=20=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E5=9B=9E=E8=B0=83=E6=A8=A1=E5=BC=8F=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81callback=E5=92=8Cpromise?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .babelrc | 5 +- example/main.js | 2 + example/routers/index.vue | 1 + example/routers/pullRefresh.vue | 134 ++++++++++++++++++ package.json | 3 + .../pullrefresh/src/pullrefresh.vue | 10 +- 6 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 example/routers/pullRefresh.vue diff --git a/.babelrc b/.babelrc index e027e954..fb53b482 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,6 @@ { "presets": [ - ["es2015"] - ] + ["env","stage-2"] + ], + "plugins": ["transform-runtime"] } diff --git a/example/main.js b/example/main.js index ef017787..10ca0547 100644 --- a/example/main.js +++ b/example/main.js @@ -49,6 +49,7 @@ import CheckList from './routers/checklist.vue'; import Search from './routers/search.vue'; import ScrollNav from './routers/scrollnav.vue'; import Preview from './routers/preview.vue'; +import PullRefresh from './routers/pullRefresh.vue'; import App from './app.vue'; @@ -107,6 +108,7 @@ const router = new VueRouter({ {path: '/search', name: 'search', component: Search}, {path: '/scrollnav', name: 'scrollnav', component: ScrollNav}, {path: '/preview', name: 'preview', component: Preview}, + {path: '/pullRefresh', name: 'pullRefresh', component: PullRefresh}, ] }); diff --git a/example/routers/index.vue b/example/routers/index.vue index 33f51222..fac056e4 100644 --- a/example/routers/index.vue +++ b/example/routers/index.vue @@ -52,6 +52,7 @@ {icon: 'demo-icons-scrollnav', name: 'ScrollNav', link: '/scrollnav'}, {icon: 'demo-icons-scrolltab', name: 'ScrollTab', link: '/scrolltab'}, {icon: 'demo-icons-preview', name: 'Preview', link: '/preview'}, + {icon: 'demo-icons-preview', name: 'PullRefresh', link: '/pullRefresh'}, ] } } diff --git a/example/routers/pullRefresh.vue b/example/routers/pullRefresh.vue new file mode 100644 index 00000000..41b44692 --- /dev/null +++ b/example/routers/pullRefresh.vue @@ -0,0 +1,134 @@ + + + + + + + {{item.title}} + + + ¥{{item.marketprice}} + ¥{{item.productprice}} + + content + + + + + Promise + Callback + + + + + diff --git a/package.json b/package.json index 9a9d5c3e..9fd6ac91 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,10 @@ "autoprefixer": "^6.6.1", "babel-core": "^6.21.0", "babel-loader": "^6.2.10", + "babel-plugin-transform-runtime": "^6.23.0", + "babel-preset-env": "^1.7.0", "babel-preset-es2015": "^6.18.0", + "babel-preset-stage-2": "^6.24.1", "css-loader": "^0.26.1", "extract-text-webpack-plugin": "^1.0.1", "file-loader": "^0.10.1", diff --git a/src/components/pullrefresh/src/pullrefresh.vue b/src/components/pullrefresh/src/pullrefresh.vue index 1b7198b0..bf3facd2 100644 --- a/src/components/pullrefresh/src/pullrefresh.vue +++ b/src/components/pullrefresh/src/pullrefresh.vue @@ -218,9 +218,15 @@ this.resetParams(); }, - triggerLoad() { + async triggerLoad() { this.touches.loading = true; - this.callback && this.callback(); + var fn = this.callback&&this.callback(); + if(fn&&fn.then&&typeof fn.then =='function'){ + let ser = await fn; + if(ser){ + this.resetParams(); + } + } }, resetParams() { this.dragTip.translate = 0;