vue.js - 如何从 route.params 中获取 id 从 vuex 的数组中找到它并获取此 id 的标题字段
解决方案
以下示例是否回答了您的问题?
// short
const title = this.$store.state.ALL_CATS.find(element => element.id == this.$route.params.id).title;
// breakdown
const id = this.$route.params.id;
const cats = this.$store.state.ALL_CATS;
const cat = cats.find(element => element.id == id);
const title = cat.title;
推荐阅读
- python - Flask-RESTplus 中的响应类
- r - R - 为多个变量查找一周中同一天的变化并聚合
- python-3.x - 如何在 Python 中有效地追加运行总和?
- node.js - 除非从新的浏览器选项卡加载页面,否则 Node Express 应用程序会冻结
- javascript - v-显示嵌套数组项是否匹配过滤数组
- java - 我应该把 public static void main(String[] args) 放在哪里?
- javascript - 数学程序中的 JavaScript 输出
- c++ - 错误 E0289:没有构造函数“Movie::Movie”的实例与基本程序 (C++) 的参数列表匹配
- r - 如何在 R 中优化这种逐行粘贴?
- javascript - useState 变量在组件中是正确的,但在它所在的自定义钩子中不正确