2025年02月20日 建站教程
vue项目中如何重新渲染组件(刷新组件),下面web建站小编给大家简单介绍一下实现代码!
新建一个js文件
const state = { viewId: 1 }; const getters = { getViewId: state => { return state.viewId; } }; const mutations = { setViewId: (state, payload) => { state.viewId++; } }; const actions = { setViewId: (context, payload) => { context.commit("setViewId", payload); } }; export default { namespaced: true, state, getters, mutations, actions };
引入到.vue文件执行
methods: { fresh() { this.$store.dispatch("view/setViewId") } }
本文链接:http://so.lmcjl.com/news/23529/