使用 vue 构建项目时, 目前对于页面刷新,
用户体验效果较好的是 provide + inject
具体使用方法如下, PS(回去要补充下原理)
1. 在 App.vue 中修改如下:
- <router-view v-if="isRouterAlive">
- </router-view>
- export default {
- name: 'App', // 实现路由跳转, 页面刷新 provide () {
- return {
- reload:
- this.reload
- }
- }, data () {
- return {
- isRouterAlive: true
- }
- }, methods: {
- reload () {
- this.isRouterAlive = false this.$nextTick(function () {
- this.isRouterAlive
- = true
- })
- }
- }
- }
2. 在要进行刷新的页面中修改:
一般写在 name 下面,
inject:['reload']
然后再需要刷新的地方调用 this.reload() 即可
来源: http://www.qdfuns.com/article/36713/ed9c6200fedd2c44e1971c7de62dea7c.html