> For the complete documentation index, see [llms.txt](https://learnmagento.gitbook.io/vuejs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnmagento.gitbook.io/vuejs/ep17-08-mapmutations-va-mot-vai-luu-y-khi-lam-vue.js-ok.md).

# Ep17#08 - mapMutations và một vài lưu ý khi làm Vue.js (ok)

C:\Users\Administrator\Desktop\imoney\package.json

```
{
  "name": "Aaaaaaaa",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.8.3",
    "vue": "^2.6.14",
    "vue-router": "3.6.5",
    "vuex": "2.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "vue-template-compiler": "^2.6.14"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}
```

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

```
<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

```
<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

```
<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

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

```

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

```
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;
    },
    decrement(state){
      state.result--
    }
  }
})
```

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

```
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')
```

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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-08-mapmutations-va-mot-vai-luu-y-khi-lam-vue.js-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.
