<el-button type="primary" @click="save">保存</el-button>
时间: 2023-10-06 21:04:29 浏览: 74
基于elementUI的el-button的vue版404 500 403 页面
Thank you for providing more context. The error message "unexpected mutation" in Vue3 is typically related to the use of the reactive API.
When you see this error message, it usually means that you are trying to modify a reactive object outside of a mutation function. In Vue3, you need to use a mutation function to modify reactive objects in order to ensure that the changes are tracked properly by the reactivity system.
In your case, it's possible that the `save` method is modifying a reactive object without using a mutation function. To fix the issue, you should wrap the code that modifies the reactive object inside a `commit` function call.
For example, if you have a reactive object called `myObject`, you should modify it like this:
```
const save = () => {
store.commit('updateMyObject', newValue);
}
```
And then define the `updateMyObject` mutation function in your Vuex store:
```
const store = createStore({
state: {
myObject: { /* initial value */ }
},
mutations: {
updateMyObject(state, newValue) {
state.myObject = newValue;
}
}
});
```
I hope this helps! Let me know if you have any further questions.
阅读全文