12345678910111213141516171819202122232425262728293031323334353637 |
- import Vuex from 'vuex'
- const createStore = () => {
- return new Vuex.Store({
- state: {
- headlines: [],
- loading: false,
- category: ''
- },
- mutations: {
- setHeadLines (state, headlines) {
- state.headlines = headlines
- },
- setLoading (state, loading) {
- state.loading = loading
- },
- setCategory (state, category) {
- state.category = category
- }
- },
- actions: {
- async loadHeadLines ({ commit }, apiUrl) {
- commit('setLoading', true)
- const { articles } = await this.$axios.$get(apiUrl)
- commit('setLoading', false)
- commit('setHeadLines', articles)
- }
- },
- getters: {
- headlines: state => state.headlines,
- loading: state => state.loading,
- category: state => state.category
- }
- })
- }
- export default createStore
|