教程部分 getters 对象里面函数简写的疑问
getArticleById: (state) => (id) => {}
和
getArticleById: (state,id) => {}
有什么区别吗?
为什么第二种会报错:
报错信息如下:
vue-router.esm.js?8c4f:2257 TypeError: store.getters.getArticleById is not a function
at eval (index.js?a18c:27)
at iterator (vue-router.esm.js?8c4f:2300)
at step (vue-router.esm.js?8c4f:1947)
at eval (vue-router.esm.js?8c4f:1948)
at eval (vue-router.esm.js?8c4f:2322)
at VueComponent.beforeRouteLeave (Create.vue?56af:52)
at boundRouteGuard (vue-router.esm.js?8c4f:2450)
at iterator (vue-router.esm.js?8c4f:2300)
at step (vue-router.esm.js?8c4f:1947)
at runQueue (vue-router.esm.js?8c4f:1955)
有点不懂,望赐教!
不简写的情况下,应该是这样的。 getArticleById 方法返回了一个函数。
第一次简写,使用箭头函数
再次简写:
最后一次简写,使用箭头函数省略了 return