代码拉取完成,页面将自动刷新
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)
// }
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。