Vuex 只修改对象里的某一个值
时间: 2023-08-22 17:03:25
浏览: 357
![ZIP](https://csdnimg.cn/release/download/static_files/pc/images/minetype/ZIP.png)
smartTable:表格动态修改
在 Vuex 中,如果你只想修改一个对象中的某个属性,可以通过以下步骤实现:
1.在 state 中定义对象以及属性
```javascript
state: {
user: {
name: 'John',
age: 25,
email: 'john@gmail.com'
2.在 mutations 中定义更新对象属性的方法
```javascript
mutations: {
updateUserName(state, name) {
state.user.name = name
3.在组件中使用 $store.commit 方法来调用该方法
```javascript
this.$store.commit('updateUserName', 'Jack')
这样就可以只修改对象里的某一个值了。注意,这里我们直接修改了 state 中的属性,因为 Vuex 的状态是响应式的,所以这个修改会自动触发视图的更新。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)