vue.js - 使用动态名称作为参数 Vuejs
问题描述
我有多个参数,当我执行获取请求时,我只想拥有一个函数,该函数采用参数名称及其值。
问题是,参数是我定义的,而不是值。
this.debounce("search_fullname", 5);
debounce(searchField, value) {
this.$router.push({
query: {
...this.$route.query,
searchField: value
}
})
}
在我得到的网址中,/?searchField=5
而不是/?search_fullname=5
解决方案
this.debounce("search_fullname", 5);
debounce(searchField, value) {
this.$router.push({
query: {
...this.$route.query,
[searchField]: value <--- Dynamic key in js object
}
})
}
你应该得到/?search_fullname=5
而不是/?searchField=5
在 url 中。
推荐阅读
- ios - 在 SwiftUI 中构建一个自定义的类 TabView 视图
- visual-studio-code - 如何使用命令行在 VSCode 中安装多个扩展
- sorting - 对电子元件列表进行排序?
- php - 获取用户 GridView Yii2 的父名称
- java - 为什么我的执行程序服务线程挂在 java 中?
- mongodb-query - 如何总结 Mongoshell 中的两个字段?
- c - 反向遍历链表的函数的空间复杂度分析?
- android - 如何让 ViewModel 观察者最初不观察?
- python - Matplotlib 为什么我收到“ValueError:查看限制最小值 0.0 小于 1 并且是无效的 Matplotlib 日期值”?
- javascript - 解构复杂对象