gpt4 book ai didi

javascript - UI 路由器 $stateParams 是只读的

转载 作者:行者123 更新时间:2023-11-28 04:38:09 25 4
gpt4 key购买 nike

我目前正在使用 $stateParams 将 id 传递到新状态。工作正常,但是如果用户重新加载页面怎么办?显然,$stateParams 中不会有任何值。解决这个问题的方法是在初始页面加载时将 $stateParam id 加载到 localStorage 中。重新加载时,如果 $stateParams 的 id 不存在,则手动分配它。例如:

// Ensure params are set when page is reloaded
if (!$stateParams.id) {
$stateParams.id = localStorageService.get('campaignId');
$state.go($state.current, $stateParams);
}

在我的本地机器上这是有效的。但是在我的开发服务器上,我收到此错误:

Cannot assign to read only property 'id' of object '#<Object>' .

有没有办法让 $stateParams 可写?

希望这是有道理的,提前致谢。

最佳答案

这对我有用

let $stateParams = Object.assign({}, $transition$.params());

关于javascript - UI 路由器 $stateParams 是只读的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44010969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com