1 Star 0 Fork 0

animalcoder/Vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
store.js 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
animalcoder 提交于 2020-03-23 09:59 +08:00 . Vue6
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
let defaultlist=[{title1:"test",content1:"test",id:"1"}]
try {//
if(localStorage.getItem("list1")){
defaultlist=JSON.parse(localStorage.getItem("list1"))
}
}catch(e){
}
let defaultid=2;
try {//
if(localStorage.getItem("id1")){
defaultid=JSON.parse(localStorage.getItem("id1"))
}
}catch(e){
}
export default new Vuex.Store({
state:{//状态
lists:defaultlist
, id:defaultid
},
mutations: { //更改事件
addItems (state , value){
state.lists.push(value)
localStorage.setItem("list1",JSON.stringify(state.lists))
},
},
actions: {
},
getters: {
getTodoById: (state) => (id) => {
return state.lists.find(todo => (todo.id == id))
},
getTodoById2:function(state,actions){
let x=function(id) {
return state.lists.find(todo => todo.id === id)
}
console.log("x"+x)
return x;
},
// getTodoById2(id) {
// return this.state.lists.find(todo => todo.title1 === id)
// }
}
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/animalcoder/Vue.git
git@gitee.com:animalcoder/Vue.git
animalcoder
Vue
Vue
master

搜索帮助