# Ep17#07 - Mutations thay đổi state từ components (ok)

<figure><img src="/files/xXzrPPBmWSb7PewXGpkX" alt=""><figcaption></figcaption></figure>

C:\Users\Administrator\Desktop\imoney\src\components\AppResult.vue

```html
<template>
  <div>
   {{ result }}
  </div>
</template>
<script>
export default {
  name: 'AppCount',
  computed: {
    result(){
      return this.$store.state.result;
    }
  }
}
</script>
```

C:\Users\Administrator\Desktop\imoney\src\App.vue

```html
<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <AppResult />
    <br/>
    <OtherResult />
    <br/>
    <app-count />
  </div>
</template>
<script>
import AppCount from './components/AppCount.vue'
import AppResult from './components/AppResult.vue'
import OtherResult from './components/OtherResult.vue'
export default {
  name: 'App',
  components: {
    AppResult,
    AppCount,
    OtherResult
  }
}
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

```

C:\Users\Administrator\Desktop\imoney\src\components\OtherResult.vue

```html
<template>
  <div>
   <!-- <p>{{ result }}</p> -->
   <!-- <p>{{ nameResult }}</p> -->
   <p style="color: red;">{{ testResult }}</p>
   <p style="color: green;">{{ nameResult }}</p>
  </div>
</template>
<script>
import {mapGetters} from 'vuex';
export default {
  name: 'AppCount',
  // computed: {
  //   result() {
  //     return this.$store.getters.testResult
  //   },
  //   nameResult() {
  //     return this.$store.getters.nameResult
  //   }
  // },
  // Use short
  computed: {
    ...mapGetters(['testResult', 'nameResult'])
  }
}
</script>
```

C:\Users\Administrator\Desktop\imoney\src\components\AppCount.vue

```html
<template>
  <div>
    <button @click="increment">Increment</button>
    <button @click="decrement">Decrement</button>
  </div>
</template>
<script>
export default {
  name: 'AppCount',
  methods: {
    increment() {
      // this.$store.state.result++
      this.$store.commit('incrementOp',5);
    },
    decrement() {
      this.$store.state.result--
    }
  }
}
</script>

```

C:\Users\Administrator\Desktop\imoney\src\store.js

```html
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export const store = new Vuex.Store({
  state: {
    result: 0
  },
  getters: {
    testResult: state => {
      return state.result * 10;
    },
    nameResult: state => {
      return state.result * 10 + " name products";
    }
  },
  mutations: {
    incrementOp(state,nuber=1) {
      state.result += nuber;
    }
  }
})
```

C:\Users\Administrator\Desktop\imoney\src\main.js

```javascript
import Vue from 'vue'
import App from './App.vue'
import {store} from './store.js'
Vue.config.productionTip = false
new Vue({
  store,
  render: h => h(App),
}).$mount('#app')
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnmagento.gitbook.io/vuejs/ep17-07-mutations-thay-doi-state-tu-components-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
