Skip to content

Commit 477a144

Browse files
sametaylakf
authored andcommitted
vue-wait transition feature (#70)
1 parent ee61dcf commit 477a144

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

examples/transition-example/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Vue from 'vue';
2+
import VueWait from '../../src/vue-wait';
3+
4+
import main from './main.vue';
5+
6+
Vue.use(VueWait);
7+
8+
new Vue({
9+
el: '#app',
10+
wait: new VueWait({ registerComponents: false }),
11+
render: function(createElement) {
12+
return createElement(main);
13+
}
14+
});

examples/transition-example/main.vue

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<template>
2+
<div id="app">
3+
<button @click.prevent="getUsers">Get Users</button>
4+
<div class="transitions-demo">
5+
<div>
6+
<h2>With transition</h2>
7+
<v-wait for="users" transition="fade" mode="out-in">
8+
<template slot="waiting">
9+
<p>Loading...</p>
10+
</template>
11+
12+
<ul>
13+
<li>One</li>
14+
<li>Two</li>
15+
<li>Three</li>
16+
<li>Four</li>
17+
<li>Five</li>
18+
</ul>
19+
</v-wait>
20+
</div>
21+
22+
<div>
23+
<h2>Without transition</h2>
24+
<v-wait for="users">
25+
<template slot="waiting">
26+
<p>Loading...</p>
27+
</template>
28+
29+
<ul>
30+
<li>One</li>
31+
<li>Two</li>
32+
<li>Three</li>
33+
<li>Four</li>
34+
<li>Five</li>
35+
</ul>
36+
</v-wait>
37+
</div>
38+
</div>
39+
</div>
40+
</template>
41+
42+
<script>
43+
export default {
44+
name: "App",
45+
methods: {
46+
getUsers() {
47+
return new Promise(resolve => {
48+
this.$wait.start("users");
49+
setTimeout(() => {
50+
resolve();
51+
this.$wait.end("users");
52+
}, 5000);
53+
});
54+
}
55+
}
56+
};
57+
</script>
58+
59+
<style>
60+
#app {
61+
display: flex;
62+
flex-direction: column;
63+
justify-content: center;
64+
}
65+
66+
.transitions-demo {
67+
display: flex;
68+
justify-content: space-around;
69+
}
70+
71+
.fade-enter-active,
72+
.fade-leave-active {
73+
transition: opacity 2s;
74+
}
75+
76+
.fade-enter,
77+
.fade-leave-to {
78+
opacity: 0;
79+
}
80+
</style>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"test": "exit 0;",
3232
"precommit": "lint-staged",
3333
"build": "cross-env NODE_ENV=production webpack --config webpack.config.js",
34+
"dev-transition": "poi examples/transition-example/index.js",
3435
"dev-vuex": "poi examples/vuex-example/index.js",
3536
"dev-vue": "poi examples/vue-example/index.js",
3637
"dev-wrap": "poi examples/wrap-example/index.js",

src/components/v-wait.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<template lang="html">
2-
<div>
2+
<transition :name='transition' :mode='mode'>
33
<span v-if='waitsFor'>
44
<slot name='waiting'></slot>
55
<span v-if='message'>{{ message }}</span>
66
</span>
77
<slot v-else></slot>
8-
</div>
8+
</transition>
99
</template>
1010
<script>
1111
export default {
1212
props: {
1313
visible: Boolean,
14+
transition: String,
15+
mode: String,
1416
for: String,
1517
message: String,
1618
},

0 commit comments

Comments
 (0)