Several incomprehensible problems in state.js action.js type.js mutations.js in vuex

state.js:
const state={
    article:localStorage["article"]?JSON.parse(localStorage["article"]): [],
    collections:localStorage["collections"]?JSON.parse(localStorage["collections"]): [],
    carts:localStorage["carts"]?JSON.parse(localStorage["carts"]): [],
    orders:localStorage["orders"]?JSON.parse(localStorage["orders"]): [],
    todos:localStorage["todos"]?JSON.parse(localStorage["todos"]): [],
    address:localStorage["address"]?JSON.parse(localStorage["address"]): [],
    nowIndex:0,
    arr:[1,2,3,4,5]
}

export default state
action.js:
const actions={
    //
    setCart({commit},data){
        commit("SET_CARTS",data)
    },
    
    //
    setArticle({commit},data){
        commit("SET_ARTICLE",data)
    },
    //
    setGoods({commit},data){
        commit("SET_GOODS",data)
    },
    //
    setAddress({commit},data){
        commit("SET_ADDRESS",data)
    },
    //
    setOrders({commit},data){
        commit("SET_ORDERS",data)
    }
}

export default actions
type.js:
export const SET_CARTS = "SET_CARTS"  //
export const SET_ARTICLE ="SET_ARTICLE" //
export const SET_GOODS="SET_GOODS" //
export const SET_ORDERS="SET_ORDERS" //
export const SET_ADDRESS="SET_ADDRESS" //
import state from "./state"
import * as type from "./type.js"
import { MessageBox } from "mint-ui";

const matutaions={
    //
    [type.SET_CARTS](state,data){
        state.carts.push(data)
        localStorage.setItem("carts",JSON.stringify(state.carts));
    },
    //
    [type.SET_ARTICLE](state,data){
        state.article.push(data)
        localStorage.setItem("article",JSON.stringify(state.article));
    },
    //
    [type.SET_GOODS](state,data){
        state.collections.push(data)
        localStorage.setItem("collections",JSON.stringify(state.collections));
    },
    //
    [type.SET_ORDERS](state,data){
        state.orders.push(data)
        localStorage.setItem("orders",JSON.stringify(state.orders));
    },
    //
    [type.SET_ADDRESS](state,data){
        state.address.push(data)
        localStorage.setItem("address",JSON.stringify(state.address));
    },
    //
    del:(state,index)=>{
        MessageBox.confirm("").then(action=>{
            state.article.splice(index,1)
            localStorage.setItem("article",JSON.stringify(state.article));
        })
    },
    //
    cancel:(state,index)=>{
        MessageBox.confirm("").then(action=>{
            state.collections.splice(index,1)
            localStorage.setItem("collections",JSON.stringify(state.collections));
        })
    },
    laji:(state,index)=>{
        MessageBox.confirm("").then(action=>{
            state.address.splice(index,1)
            localStorage.setItem("address",JSON.stringify(state.address));
        }) 
    },
    //
    shanchu:(state,index)=>{
        MessageBox.confirm("").then(action=>{
            state.carts.splice(index,1)
            localStorage.setItem("carts",JSON.stringify(state.carts));
        })
    },
    //
    odefault:(state,index)=>{
        MessageBox.confirm("").then(action=>{
            state.orders.splice(index,1)
            localStorage.setItem("orders",JSON.stringify(state.orders));
        })
    },
   

    //
     add(state,index){
        state.carts[index].valuePP
    },
    //
    reduce(state,index){
        state.carts[index].value==1?state.carts[index].value=1: state.carts[index].value--
    },

    settlement:(state,data)=>{
        state.carts=[];
        localStorage.setItem("carts",JSON.stringify(state.carts));
    },
}

export default matutaions

the above code comes from a github project, which I downloaded and studied by myself. Here are a few questions to ask you.
1. What role does type.js play in the whole structure of vuex? I didn"t see it when I was learning vuex. Why did I write it this way? Does it have to be written like this?
2, there are some methods for action.js in vuex, but not all of them, that is, why / / address

[type.SET_ADDRESS](state,data){
    state.address.push(data)
    localStorage.setItem("address",JSON.stringify(state.address));
},
//
del:(state,index)=>{
    MessageBox.confirm("").then(action=>{
        state.article.splice(index,1)
        localStorage.setItem("article",JSON.stringify(state.article));
    })
},

is also the method in vuex, some methods are written in [type.SET_ADDRESS] above, and some can be used directly like del, so why write two?
3. As soon as vuex refreshes the browser, then the state data in vuex disappears. I found localstorage,. Is this the best way?

Mar.24,2021

tell me about my personal understanding.
about type.js

in a nutshell, type.js is just a reference, or a mapping of strings.
type.js brings these string together so that you can see intuitively what state your module or app has and what state changes it has.
here is the official explanation: ide/mutations.html-sharp%E4%BD%BF%E7%94%A8%E5%B8%B8%E9%87%8F%E6%9B%BF%E4%BB%A3-mutation-%E4%BA%8B%E4%BB%B6%E7%B1%BB%E5%9E%8B" rel=" nofollow noreferrer "> https://vuex.vuejs.org/zh/gui..

// type.js
export const GET_LIST = 'GET_ORDER_LIST'
// action.js
[types.GET_LIST](...) {...} // string: GET_ORDER_LIST(...) {...}

as for the second question, I can only say that it is the specification of the code. Of course, you can not use type.js, as long as you can make sure that the name of action does not conflict. But personally, it is recommended to use only one at the same time, either with type, or none at all.

with regard to data persistence, refer to some current plug-ins, which are also used by localStorage,. I also use localStorage and sessionStorage,. If there are more or better ways, please let me know: -).


1. Type.js, is really just a standardized management method, which defines all mutations operations in type.js.
2, storage method. The plug-in vuex-persistedstate is currently used in the project. LocalStorage is used by default. Of course you can choose SessionSorage and cookie. These choices are based on your understanding of the differences between them and based on the needs of the project. There is no best, only the most suitable

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b696-2c285.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b696-2c285.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?