先发吧数据发送到store.js里代码如下,通过store.commit发送("", ),store.state接收

setup(props, ctx) {
const data = reactive({
  name:'',
  qwe:store.state.list,   //获取vuex里的list数据
 
});

const add=()=>{
 store.commit("add",data.name)   //store.commit()发送数据
}
return { ...toRefs(data),add };
}

store.js里代码

import { createStore } from 'vuex'
import vuexPersist from "vuex-persist";
export default createStore({
  state: {
    list:[]
  },
  mutations: {
    add(state,val){
      state.list.push({name:val,id:0})
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
})

记得下载vuex 和cnpm i vuex-persist -S!!!!!!!

Logo

前往低代码交流专区

更多推荐