nuxt/todomvc

Classic mode for store/ is deprecated and will be removed in Nuxt 3.

Closed this issue · 1 comments

How to fix it?

index.js

import Vue from 'vue' // Can not find module
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

const store = () => new Vuex.Store({
state: {
todos: []
},
getters: {
allTodos (state) { //Parameter 'state' implicitly has an 'any' type.ts(7006)
return state.todos
},
activeTodos (state) {
return state.todos.filter(todo => !todo.completed)
},
completedTodos (state) {
return state.todos.filter(todo => todo.completed)
}
},
mutations: {
SET_TODOS (state, todos) {
state.todos = todos
},
ADD_TODO (state, todo) {
state.todos.push(todo)
},
REMOVE_TODO (state, todo) {
var i = state.todos.indexOf(todo)
state.todos.splice(i, 1)
},
FILTER_TODOS (state, value) {
state.todos.forEach((todo) => {
todo.completed = !value
})
}
},
actions: {
addTodo ({ commit }, todo) {
commit('ADD_TODO', todo)
},
setTodos ({ commit }, todos) {
commit('SET_TODOS', todos)
},
removeTodo ({ commit }, todo) {
commit('REMOVE_TODO', todo)
},
allDone ({ state, commit }) {
var value = state.todos.filter(todo => todo.completed).length === state.todos.length
commit('FILTER_TODOS', value)
},
saveTodos ({ state }) {
axios.put('/api/todos', { todos: state.todos })
},
nuxtServerInit ({ commit }, { req }) {
commit('SET_TODOS', req.session ? (req.session.todos || []) : [])
}
}
})

export default store

This question is available on Nuxt community (#c18)

This issue as been imported as question since it does not respect todomvc issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/todomvc/issues/c18.