iview-admin icon indicating copy to clipboard operation
iview-admin copied to clipboard

当标签带有动态参数时,切换时不执行mounted事件

Open maysoft opened this issue 9 years ago • 18 comments

router如下 { path: '/order', redirect: '/order/index', icon: 'ios-cart', name: 'order', title: '订单管理', component: Main, children: [ { path: 'List/:username(.)?_:agent(.)?:soft(.*)?:start(.)?_:end(.)?:pageindex*:pagesize*', icon: 'compose', name: 'order-list', title: '订单列表', component: resolve => { require(['./views/my_pages/order/list.vue'], resolve); } } ] }

我在mounted里根据url参数获取不同的内容,之前切换标签刷新时没问题,现在更新到新版缓存方式时,当参数不一样时,不再执行mounted事件了。 http://localhost:8080/#/order/List/______ http://localhost:8080/#/order/List/test025__0___1_10

maysoft avatar Oct 23 '17 06:10 maysoft

你这种我个人觉得你获取数据的方法应该放在watch里监听路由的变化

watch:{
     '$route' () {
        // getData();
    }
}

lison16 avatar Oct 23 '17 07:10 lison16

//检测路由变化 $route: function(to, from) { console.log("route"); if (this.$route.params.username) this.searchOption.username = this.$route.params.username; //else this.searchOption.username='';

  if (this.$route.params.agent)
    this.searchOption.agent = this.$route.params.agent;

  if (this.$route.params.soft)
    this.searchOption.soft = this.$route.params.soft;

  if (this.$route.params.start)
    this.searchOption.start = this.$route.params.start;
  if (this.$route.params.end)
    this.searchOption.end = this.$route.params.end;

  if (this.$route.params.pageindex)
    this.page.pageindex = parseInt(this.$route.params.pageindex);
  if (this.$route.params.pagesize)
    this.page.pagesize = parseInt(this.$route.params.pagesize);
  this.InitData();
}

试了下 这样同一个链接 来回切换都会刷新 缓存方式不起作用了

maysoft avatar Oct 23 '17 07:10 maysoft

image 贴一张图吧

maysoft avatar Oct 23 '17 07:10 maysoft

还有一个问题,这样wach后,切换另外跟这个页面不相关的标签时 也会调用这块代码

maysoft avatar Oct 23 '17 08:10 maysoft

image 暂时只能这么做了,新手,忘见谅。感觉缓存里根据name当主键是不是不妥?

maysoft avatar Oct 23 '17 08:10 maysoft

这个功能做的比较急,还在完善,望持续关注,暂时排期还有一个问题待完善,很快解决之后就会优化页面缓存问题。

lison16 avatar Oct 23 '17 08:10 lison16

恩 不着急,我也是边学边做,遇到问题就先反馈了。有现成的解决方案比我瞎折腾方便多了。

maysoft avatar Oct 23 '17 08:10 maysoft

页面状态缓存后面换成path来管理,还有,缓存的页面用activated和deactivated这两个钩子

lison16 avatar Oct 30 '17 03:10 lison16

恩 我觉得先优化这块比较好,因为这是最主要的功能使用频率最高的, 其他的功能性东西可以慢慢加

maysoft avatar Oct 30 '17 03:10 maysoft

尊敬的作者: 请问这个问题已经修复了吗?目前我这里也碰到标签页数据不刷新的问题。

alspxl avatar Dec 05 '17 08:12 alspxl

一样的问题, 带有动态参数不执行mounted

Zhengbledore avatar Dec 05 '17 08:12 Zhengbledore

@Zhengbledore @alspxl 你们的iview-admin版本是多少?为什么我的就执行mounted

lison16 avatar Dec 05 '17 08:12 lison16

@lison16 10月十几号左右的版本, 看了下你的更新日志,似乎没有关于上面的相关更新

Zhengbledore avatar Dec 05 '17 09:12 Zhengbledore

@lison16 那我今晚把下载最新的试试, 谢谢

Zhengbledore avatar Dec 05 '17 09:12 Zhengbledore

我现在用最新的试没有出现这个问题

lison16 avatar Dec 05 '17 09:12 lison16

很抱歉, 更新到最新的发布版本也是一样的情况。 比如我在有一个分类列表, 选择分类为ID为4的 edit-article-category/4, 第一次进去顺利, 但是当我返回列表点击id为3的,uri变成了edit-article-category/3 但是mounted里面的 代码并没有执行。

然后我现在只能在这些编辑表单中,把这些页面的name给改成跟路由的name不一样的

Zhengbledore avatar Dec 05 '17 23:12 Zhengbledore

如果你这个页面是被keep-active缓存的,那mouted肯定不会每次都触发,那要用activated

lison16 avatar Dec 06 '17 01:12 lison16

@lison16 懂了,谢谢你,爱你哦,么么哒。

Zhengbledore avatar Dec 06 '17 02:12 Zhengbledore