You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-21Lines changed: 11 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -681,38 +681,28 @@ Easy. Instead of defining `metaInfo` as an object, define it as a function and a
681
681
682
682
## How do I populate `metaInfo` from the result of an asynchronous action?
683
683
684
-
`vue-meta`exposes a method called `refresh` on the client-side that allows you to trigger an update at any given point in time.
684
+
`vue-meta`will do this for you automatically when your component state changes.
685
685
686
-
In the same way you access `$meta().inject()` on the server, you can access `$meta().refresh()`.
687
-
688
-
For example, if you're using Vuex and you have an action that fetches a `post` asynchronously, you should ensure that it returns a promise so that you are notified when the fetching is complete:
686
+
Just make sure that you're using the function form of `metaInfo`:
689
687
690
688
```js
691
689
{
692
-
actions: {
693
-
asyncfetchPost ({ commit }, payload) {
694
-
constpost=yielddb.fetch('posts', payload.postId)
695
-
commit('fetchedPost', post)
690
+
data () {
691
+
return {
692
+
title:'Foo Bar Baz'
696
693
}
697
694
}
698
-
}
699
-
```
700
-
701
-
Then in your component, you can call `refresh()` to trigger an update once the fetch is complete:
702
-
703
-
```js
704
-
{
705
-
beforeMount () {
706
-
constpostId=this.$router.params.id
707
-
this.$store.dispatch('fetchPost', { postId })
708
-
.then(() =>this.$meta().refresh())
695
+
metaInfo () {
696
+
return {
697
+
title:this.title
698
+
}
709
699
}
710
700
}
711
701
```
712
702
713
-
Just make sure that whatever data source you're using (`store` if you're using Vuex, component `data` otherwise) has some sane defaults set so Vue doesn't complain about `null` property accessors.
703
+
Check out the [vuex-async](https://github.com/declandewet/vue-meta/tree/master/examples/vuex-async) example for a far more detailed demonstration if you have doubts.
714
704
715
-
Check out the [vuex-async](https://github.com/declandewet/vue-meta/tree/master/examples/vuex-async) example for a far more detailed demonstration of how this works.
705
+
Credit & Thanks for this feature goes to [Sébastien Chopin](https://github.com/Atinux).
0 commit comments