簡體   English   中英

如何使用具有組合 api 的 vuex 模塊吸氣劑?

[英]How to use vuex modules getters with composition api?

這是我的 vuex 吸氣劑

const getters = {
 getMovieById: state => id => {
 debugger;
 return state.movies.find(movie => movie.id === id);
 }
};

我在我的組件中導入模塊

import movieMod from "../store/modules/movies";

我將 getter 的返回值存儲在我的反應式 object

 movie = movieMod.getters.getMovieById(parseInt(props.id));

這讓我跟隨 function

(id) {
  debugger;
  return state.movies.find(function (movie) {
    return movie.id === id;
  });
}

Try the following movie = movieMod.getters.getMovieById(state)(parseInt(props.id) . getMovieById is a Higher Order Function, which is a function that returns a function. In your case, you are not executing the returned function.

我發現我的方法是錯誤的我應該使用組合 API 中的鈎子而不是導入模塊

從“vuex”導入 { useStore };

  setup(props) {
   const store = useStore();
  return {
  movie: computed(() => store.getters.getMovieById(parseInt(props.id)))
  };
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM