Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added usage with nuxtjs instructions #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,98 @@ As a default the `fade` animation will be applied. If you want to use another an
You can find a list of all available transitions in the following section.

> Notice: You can use the `vue-page-transition` component to wrap any element you would like to. The `router-view` is just the most commone use case.
## Usage With NuxtJs
To get stated simply create a "vue-page-transition.js" plugin in the plugins folder

Place the bellow code within this folder

```javascript
import Vue from 'vue'
import VuePageTransition from 'vue-page-transition'

Vue.use(VuePageTransition)
```

Import to the nuxt.comfig.js
NeniEmSu marked this conversation as resolved.
Show resolved Hide resolved
```javascript
plugins: [
...
{
src: "~/plugins/vue-page-transition",
ssr: true
},
...
],
```

```html
<vue-page-transition name="fade-in-right">
<nuxt />
</vue-page-transition>
```


## Overwrite transiton for single route in Nuxt
### Note: This where it gets tricky because nuxt doesn't make use the "meta" field as in vue-router.
The bellow are the steps to work around this issue.

1. Create a "middleware" folder with an animation.js and place these within it

```javascript
export default ({
route,
app
}) => {
const animation = route.meta.reduce((animation, meta) => meta.animation || animation, 'fade-in-up')
app.store.commit('SET_ANIMATION', animation)
}
```

2. Now go to store and in the index.js
```javascript
export const state = () => ({ // = data
...
animation: 'fade-in-up',
...
});

export const mutations = {
...,

SET_ANIMATION(state, animation) {
state.animation = animation
},

}
```
3. Import the middleware to nuxt.config.js

```javascript
export default {
router: {
middleware: ['animation']
},
css: []
}
```

4. At this point you can use it at the layout/default page like so:

```html
<vue-page-transition :name="$store.state.animation">
<nuxt />
</vue-page-transition>
```

5. Now for every route you want to add a different page transition to just add

```javascript
export default {
meta: {
animation: 'fade-in-right' // Or any of the bellow listed transition.
}
}
```

## Properties / Attributes
You can make use of the following properties in order to customize your typing expirience:
Expand Down