如何在 nuxt 中使用 getter 发送参数?
How can I send parameter with getters in nuxt?
我想在 getter 中使用 $route.params.id 发送 id,但它不起作用!
在我的组件中我有博客对象;我想将 this.$route.params.id 保存在 blogId
中,然后像这样使用我的 getters 方法传递它:
created() {
const blogId = this.$route.params.id;
console.log(blogId); ////1
this.blog=this.$store.getters.getBlogById(blogId);
console.log(this.blog);
},
但是
console.log(this.blog)
未定义
当我发送这样的号码时:
$store.getters.getBlogById(2)
有效,console.log(this.blog)
打印我的对象
我该怎么办?
我的吸气剂:
const getters = {
allBlogs: state => state.blogs,
getBlogById: (state) => (id) => {
return state.blogs.find(blog => blog.id == id)
}
}
const blogId = this.$route.params.id
- 是一个字符串,在 getter 中你使用的是 ===
,我想这就是原因。
我想在 getter 中使用 $route.params.id 发送 id,但它不起作用!
在我的组件中我有博客对象;我想将 this.$route.params.id 保存在 blogId
中,然后像这样使用我的 getters 方法传递它:
created() {
const blogId = this.$route.params.id;
console.log(blogId); ////1
this.blog=this.$store.getters.getBlogById(blogId);
console.log(this.blog);
},
但是
console.log(this.blog)
未定义
当我发送这样的号码时:
$store.getters.getBlogById(2)
有效,console.log(this.blog)
打印我的对象
我该怎么办?
我的吸气剂:
const getters = {
allBlogs: state => state.blogs,
getBlogById: (state) => (id) => {
return state.blogs.find(blog => blog.id == id)
}
}
const blogId = this.$route.params.id
- 是一个字符串,在 getter 中你使用的是 ===
,我想这就是原因。