provide+inject
这里是提供的地方
<template>
<div id="app">
<router-view v-if='isRouterAlive'/>
</div>
</template>
<script>
export default {
name: 'App',
provide () {
return {
reload: this.reload
}
},
data () {
return {
isRouterAlive: true
}
},
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
}
}
}
</script>
这里是注入的地方
<template>
<div class="onload" id="onload" @click="refresh()">
<img src="../assets/image/onload.png" alt="">
</div>
</template>
<script>
export default {
name: 'Onload',
inject: ['reload'],
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
methods: {
refresh () {
this.reload()
}
}
}
</script>
<style scoped>
</style>