javascript - 在Vue路由器推送中使用表单模型
问题描述
我正在编写一个组件来过滤网格中的数据。该组件有多个字段,我将它们的数据存储在模型中。当用户填写一些输入并提交表单时,我正在提交时执行此操作。
methods: {
async submit() {
await this.$router.push(
{
name: this.$route.name,
query: JSON.parse(JSON.stringify(this.model))
}
)
}
}
我希望这会在 URL 查询中推送表单数据,但它不会做任何事情,我会收到此错误。
Avoided redundant navigation to current location
看起来我无法将动态值传递给查询。如果我在控制台中记录模型并将确切的数据粘贴到查询代码中,它就可以正常工作!!有没有办法解决这个问题?
解决方案
尝试使用 catch 块..
this.$router.push(
{
name: this.$route.name,
query: JSON.parse(JSON.stringify(this.model))
}).catch(()=>{});
这样,它只允许您避免错误显示,因为浏览器认为异常已被处理。
推荐阅读
- r - 计算列中字典单词的频率并生成新的“dictfreq”列
- python-3.x - CVXPY 无法安装:找不到文件“setup.py”
- reactjs - 使用 Chai 测试组件时显示错误 Cannot read property 'indexOf' of undefined ,如何解决?
- angular - 为什么 ngModelChange 不能正常工作?
- excel - Excel VBA - Sharepoint 上的另存为模板不会创建新文档
- javascript - 为什么我的 .indexOf 不读取字符串中字符的位置
- python - python 3.X if 语句
- javascript - SyncFusion 选项卡中的脚本未触发
- python - 为什么 co_nlocals 返回 3,而 co_names 返回一个空元组?
- oracle-apex - 在 Oracle APEX 19.2 中动态创建密码字段