Как передать во функцию fetchPosts ище 1 параметр
<wiz-slide>
<p>{{count}}</p>
<div class = 'posts' v-for="post in allPosts" :key="post.id">
<h2>{{post.title}}</h2>
<h2>{{post.email}}</h2>
<p>{{post.body}}</p>
</div>
</wiz-slide>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
export default {
props: ['count'],
data() {
return {
type: 'posts',
id: '',
posts: [],
};
},
// computed: {
// allPosts() {
// return this.$store.getters.allPosts;
// },
// },
computed: mapGetters(['allPosts']),
methods: {
...mapActions(['fetchPosts']),
toggle() {
console.log(this.count);
this.fetchPosts(this.count, this.type);
},
},
async mounted() {
// console.log('22');
// const res = await fetch('https://jsonplaceholder.typicode.com/posts?_limit=3');
// const posts = await res.json();
// this.posts = posts;
// this.$store.dispatch('fetchPosts', 2);
console.log(this.count);
console.log('i popal');
console.log(this.type);
},
beforeUpdate() {
this.toggle();
},
};
</script>
<style scoped></style>
Vuex Сюда передаю
import Vuex from 'vuex';
import actions from './actions';
import mutations from './mutations';
export default () => new Vuex.Store({
state: {
posts: [],
},
actions: {
async fetchPosts(ctx, limit = 3, comments) {
const res = await fetch(`${`https://jsonplaceholder.typicode.com/${comments}?_limit=`}${limit}`);
const posts = await res.json();
ctx.commit('updatePosts', posts);
},
},
mutations: {
updatePosts(state, posts) {
state.posts = posts;
},
},
getters: {
allPosts(state) {
return state.posts;
},
},
modules: {
},
});