mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-23 21:30:34 +03:00
fix: Handle kept-alive components & vue-router transitions
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><a href="basic">Basic</a></li>
|
<li><a href="basic">Basic</a></li>
|
||||||
<li><a href="basic-render">Basic Render</a></li>
|
<li><a href="basic-render">Basic Render</a></li>
|
||||||
|
<li><a href="keep-alive">Keep alive</a></li>
|
||||||
<li><a href="vue-router">Usage with vue-router</a></li>
|
<li><a href="vue-router">Usage with vue-router</a></li>
|
||||||
<li><a href="vuex">Usage with vuex</a></li>
|
<li><a href="vuex">Usage with vuex</a></li>
|
||||||
<li><a href="vuex-async">Usage with vuex + async actions</a></li>
|
<li><a href="vuex-async">Usage with vuex + async actions</a></li>
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import VueMeta from 'vue-meta'
|
||||||
|
|
||||||
|
Vue.use(VueMeta)
|
||||||
|
|
||||||
|
Vue.component('foo', {
|
||||||
|
template: '<p>Foo component</p>',
|
||||||
|
metaInfo: {
|
||||||
|
title: 'Keep me Foo'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
new Vue({
|
||||||
|
template: `
|
||||||
|
<div id="app">
|
||||||
|
<h1>Kept alive foo</h1>
|
||||||
|
<button @click="show">Toggle Foo</button>
|
||||||
|
<keep-alive>
|
||||||
|
<foo v-if="showFoo"/>
|
||||||
|
</keep-alive>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
data () {
|
||||||
|
return { showFoo: false }
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
show () {
|
||||||
|
this.showFoo = !this.showFoo
|
||||||
|
}
|
||||||
|
},
|
||||||
|
metaInfo: () => ({
|
||||||
|
title: 'Keep-alive'
|
||||||
|
})
|
||||||
|
}).$mount('#app')
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<link rel="stylesheet" href="/global.css">
|
||||||
|
<a href="/">← Examples index</a>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script src="/__build__/keep-alive.js"></script>
|
||||||
@@ -46,7 +46,9 @@ const App = {
|
|||||||
<h1>vue-router</h1>
|
<h1>vue-router</h1>
|
||||||
<router-link to="/">Home</router-link>
|
<router-link to="/">Home</router-link>
|
||||||
<router-link to="/about">About</router-link>
|
<router-link to="/about">About</router-link>
|
||||||
<router-view></router-view>
|
<transition name="page" mode="out-in">
|
||||||
|
<router-view></router-view>
|
||||||
|
</transition>
|
||||||
<p>Inspect Element to see the meta info</p>
|
<p>Inspect Element to see the meta info</p>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -3,3 +3,11 @@
|
|||||||
<a href="/">← Examples index</a>
|
<a href="/">← Examples index</a>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script src="/__build__/vue-router.js"></script>
|
<script src="/__build__/vue-router.js"></script>
|
||||||
|
<style>
|
||||||
|
.page-enter-active, .page-leave-active {
|
||||||
|
transition: opacity .5s
|
||||||
|
}
|
||||||
|
.page-enter, .page-leave-to {
|
||||||
|
opacity: 0
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ export default function getComponentOption (opts, result = {}) {
|
|||||||
const { component, option, deep, arrayMerge } = opts
|
const { component, option, deep, arrayMerge } = opts
|
||||||
const { $options } = component
|
const { $options } = component
|
||||||
|
|
||||||
|
if (component._inactive) return result
|
||||||
|
|
||||||
// only collect option data if it exists
|
// only collect option data if it exists
|
||||||
if (typeof $options[option] !== 'undefined' && $options[option] !== null) {
|
if (typeof $options[option] !== 'undefined' && $options[option] !== null) {
|
||||||
let data = $options[option]
|
let data = $options[option]
|
||||||
|
|||||||
+18
-1
@@ -62,6 +62,18 @@ export default function VueMeta (Vue, options = {}) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
activated () {
|
||||||
|
if (this._hasMetaInfo) {
|
||||||
|
// batch potential DOM updates to prevent extraneous re-rendering
|
||||||
|
batchID = batchUpdate(batchID, () => this.$meta().refresh())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deactivated () {
|
||||||
|
if (this._hasMetaInfo) {
|
||||||
|
// batch potential DOM updates to prevent extraneous re-rendering
|
||||||
|
batchID = batchUpdate(batchID, () => this.$meta().refresh())
|
||||||
|
}
|
||||||
|
},
|
||||||
beforeMount () {
|
beforeMount () {
|
||||||
// batch potential DOM updates to prevent extraneous re-rendering
|
// batch potential DOM updates to prevent extraneous re-rendering
|
||||||
if (this._hasMetaInfo) {
|
if (this._hasMetaInfo) {
|
||||||
@@ -73,7 +85,12 @@ export default function VueMeta (Vue, options = {}) {
|
|||||||
if (this.$isServer) return
|
if (this.$isServer) return
|
||||||
// re-render meta data when returning from a child component to parent
|
// re-render meta data when returning from a child component to parent
|
||||||
if (this._hasMetaInfo) {
|
if (this._hasMetaInfo) {
|
||||||
batchID = batchUpdate(batchID, () => this.$meta().refresh())
|
// Wait that element is hidden before refreshing meta tags (to support animations)
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
if (this.$el.offsetParent !== null) return
|
||||||
|
clearInterval(interval)
|
||||||
|
batchID = batchUpdate(batchID, () => this.$meta().refresh())
|
||||||
|
}, 50)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user