目录
1、原生方法
- 1、原生方法
- 2、vue自带的方法
- 3、自定义全局刷新方法
location.reload();2、vue自带的方法
路由跳转
this.$router.go(0);
强制刷新API
此API也适用于uniApp,亲测有效。
this.$forceUpdate();3、自定义全局刷新方法
App.vue文件
<template> <div id="app"> <router-view v-if="isRouterAlive"> name: 'App', // 父组件中通过provide来提供变量, // 在子组件中通过inject来注入变量 provide () { return { reload: this.reload }; }, data() { return { // 控制视图是否显示的变量 isRouterAlive: true }; }, methods: { reload () { // 先关闭 this.isRouterAlive = false; this.$nextTick(function () { // 再打开 this.isRouterAlive = true; }); } } };
使用
export default { // 注入App里的reload方法 inject: ['reload'], data () { return { } }, mounted() { // 使用 // 也可以是点击触发 this.reload(); }, methods:{ } };