const test = Vue.component('test', {
mounted () {
console.log('call hook mounted')
},
data () {
return {
tip: '尼玛'
}
},
activated () {
console.log('call hook activated')
},
template: '<h1>{{tip}}</h1>'
})
const APP = new Vue({
name: 'testLifeHook',
el: document.getElementById('app'),
components: {
test
},
data () {
return {
name: 'test'
}
}
})
<html>
<body>
<div id="app">
<keep-alive include="test">
<component :is='name'></component>
</keep-alive>
</div>
</body>
</html>