Custom route example

This commit is contained in:
Sébastien Chopin 2016-12-16 17:46:30 +01:00
parent a31dc539cc
commit 36f3d48ece
7 changed files with 78 additions and 31 deletions

View File

@ -102,4 +102,19 @@ a, a:hover
.fade-enter, .fade-leave-active { .fade-enter, .fade-leave-active {
opacity: 0; opacity: 0;
} }
.bounce-enter-active {
animation: bounce-in .8s;
}
.bounce-leave-active {
animation: bounce-out .5s;
}
@keyframes bounce-in {
0% { transform: scale(0) }
100% { transform: scale(1) }
}
@keyframes bounce-out {
0% { transform: scale(1) }
100% { transform: scale(0) }
}
</style> </style>

View File

@ -11,5 +11,6 @@ module.exports = {
'/projects/:slug': [{slug: 'toto'}, {slug: 'titi'}, {slug: 'tutu'}] '/projects/:slug': [{slug: 'toto'}, {slug: 'titi'}, {slug: 'tutu'}]
} }
}, },
transition: 'fade' transition: 'fade',
loading: false
} }

View File

@ -5,14 +5,11 @@
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p> </p>
<p> <p>
<router-link :to="{ name: 'posts-slug-name', params: { name: 'foo'} }"> <nuxt-link :to="{ name: 'posts-slug-name', params: { name: 'foo'} }">Foo</nuxt-link>
Foo <nuxt-link :to="{ name: 'posts-slug-name', params: { name: 'bar'} }">Bar</nuxt-link>
</router-link> <nuxt-link :to="{ name: 'posts-slug-comments' }">Comments</nuxt-link>
<router-link :to="{ name: 'posts-slug-name', params: { name: 'bar'} }">
Bar
</router-link>
</p> </p>
<router-view></router-view> <nuxt-child :key="$route.params.name"></nuxt-child>
</div> </div>
</template> </template>

View File

@ -7,6 +7,41 @@
</div> </div>
</template> </template>
<script>
export default {
transition: {
name: 'bounce',
// css: true,
beforeEnter (el) {
console.log('Before enter');
},
enter (el) {
console.log('Enter')
// done()
},
afterEnter (el) {
console.log('After enter')
},
enterCancelled (el) {
console.log('Enter cancelled')
},
beforeLeave (el) {
console.log('Before leave')
},
leave (el) {
console.log('Leave')
// done()
},
afterLeave (el) {
console.log('After leave')
},
leaveCancelled (el) {
console.log('Leave cancelled')
}
}
}
</script>
<style scoped> <style scoped>
p p
{ {

View File

@ -3,3 +3,9 @@
Comments only Comments only
</div> </div>
</template> </template>
<style scoped>
.container {
padding: 20px;
}
</style>

View File

@ -7,7 +7,7 @@
<router-link :to="{ name: 'users-id', params: { id: user.id } }">{{ user.name }}</router-link> <router-link :to="{ name: 'users-id', params: { id: user.id } }">{{ user.name }}</router-link>
</li> </li>
</ul> </ul>
<router-view></router-view> <nuxt-child :key="$route.params.id"></nuxt-child>
</div> </div>
</template> </template>
@ -46,21 +46,4 @@ export default {
.router-link-active { .router-link-active {
color: #41b883 !important; color: #41b883 !important;
} }
.bounce-enter-active {
animation: bounce-in .8s;
}
.bounce-leave-active {
animation: bounce-out .5s;
}
@keyframes bounce-in {
0% { transform: scale(0) }
50% { transform: scale(1.5) }
100% { transform: scale(1) }
}
@keyframes bounce-out {
0% { transform: scale(1) }
50% { transform: scale(1.5) }
100% { transform: scale(0) }
}
</style> </style>

View File

@ -12,6 +12,10 @@
import axios from 'axios' import axios from 'axios'
export default { export default {
transition (to, from) {
if (!from || !from.params.id || !to.params.id) return 'fade'
return +to.params.id > +from.params.id ? 'slide-left' : 'slide-right'
},
data ({ params, error }) { data ({ params, error }) {
return axios.get(`https://jsonplaceholder.typicode.com/users/${params.id}`) return axios.get(`https://jsonplaceholder.typicode.com/users/${params.id}`)
.then((res) => { return { user: res.data } }) .then((res) => { return { user: res.data } })
@ -28,10 +32,16 @@ export default {
text-align: center; text-align: center;
overflow: hidden; overflow: hidden;
min-height: 440px; min-height: 440px;
transition: all .5s cubic-bezier(.55,0,.1,1);
}
.slide-left-enter,
.slide-right-leave-active {
opacity: 0;
transform: translate(30px, 0);
}
.slide-left-leave-active,
.slide-right-enter {
opacity: 0;
transform: translate(-30px, 0);
} }
/*.user {
text-align: center;
margin-top: 100px;
font-family: sans-serif;
}*/
</style> </style>