> For the complete documentation index, see [llms.txt](https://xml-1.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://xml-1.gitbook.io/vuejs/ep08-06-tuy-chinh-mot-su-kien-trong-component-con-and-and-ep08-08-viec-giao-thuc-qua-callback-ok.md).

# Ep08#06 - Tuỳ chỉnh một sự kiện trong component con && Ep08#08 - Việc giao thức qua Callback (ok

### **Part 1 sử dụng** name=$event

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

<figure><img src="/files/X3slVPAX12SH8yVV4Hen" alt=""><figcaption><p>Nói theo một cách dễ hiểu là bên con tạo một event, bên cha hứng event</p></figcaption></figure>

C:\Users\Administrator\OneDrive\Desktop\vuejs2\src\App.vue

```html
<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <hello-world/>
  </div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
  name: 'App',
  components: {
    HelloWorld
  }
}
</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\OneDrive\Desktop\vuejs2\src\components\HelloWorld.vue

```html
<template>
  <div class="container">
    <h1>{{ name }}</h1>
    <p>
      For a guide and recipes on how to configure / customize this project,<br>
      check out the
      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
    </p>
    <button @click="changeName">changeName</button>
    <hr>
    <div class="row">
      <div class="col-md-6">
        <hitest @resetNameParent="name=$event"></hitest>
      </div>
      <div class="col-md-6">
        <pitest></pitest>
      </div>
    </div>
  </div>
</template>
<script>
import Hitest from "./Hitest.vue";
import Pitest from "./Pitest.vue";
export default {
  name: 'HelloWorld',
  data: function() {
    return {
      name: "Skype"
    }
  },
  components: {
    Hitest,
    Pitest
  },
  methods: {
    changeName() {
      this.name = "change Name";
    }
  }
}
</script>
```

C:\Users\Administrator\OneDrive\Desktop\vuejs2\src\components\Hitest.vue

```html
<template>
  <div class="hello">
    <h1>{{ name }}</h1>
    <button @click="resetName">ResetName</button>
  </div>
</template>
<script>
export default {
  name: 'Hitest',
  data: function() {
    return {
      name: "Piiii"
    }
  },
  methods: {
    resetName() {
      this.name = "Reseted";
      this.$emit('resetNameParent',this.name);
    }
  }
}
</script>

```

C:\Users\Administrator\OneDrive\Desktop\vuejs2\src\components\Pitest.vue

```html
<template>
  <div class="hello">
    Pitest
  </div>
</template>
<script>
export default {
  name: 'Pitest'
}
</script>
```

### **Part 2 sử dụng calbackfunction**

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

<figure><img src="/files/5GYH1r9VRMoJd97SoVTY" alt=""><figcaption></figcaption></figure>

C:\Users\Administrator\OneDrive\Desktop\vuejs2\src\components\HelloWorld.vue

```html
<template>
  <div class="container">
    <h1>{{ name }}</h1>
    <p>
      For a guide and recipes on how to configure / customize this project,<br>
      check out the
      <a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
    </p>
    <button @click="changeName">changeName</button>
    <hr>
    <div class="row">
      <div class="col-md-6">
        <hitest @resetNameParent="name=$event" :resetNameFn="resetNameCallback"></hitest>
      </div>
      <div class="col-md-6">
        <pitest></pitest>
      </div>
    </div>
  </div>
</template>
<script>
import Hitest from "./Hitest.vue";
import Pitest from "./Pitest.vue";
export default {
  name: 'HelloWorld',
  data: function() {
    return {
      name: "Skype"
    }
  },
  components: {
    Hitest,
    Pitest
  },
  methods: {
    changeName() {
      this.name = "change Name";
    },
    resetNameCallback() {
      this.name = 'resetNameCallback';
    }
  }
}
</script>

```

C:\Users\Administrator\OneDrive\Desktop\vuejs2\src\components\Hitest.vue

```html
<template>
  <div class="hello">
    <h1>{{ name }}</h1>
    <button @click="resetName">ResetName</button>
    <button @click="resetNameFn">resetNameCallback</button>
  </div>
</template>
<script>
export default {
  name: 'Hitest',
  data: function() {
    return {
      name: "Piiii",
    }
  },
  props: {
    resetNameFn: Function
  },
  methods: {
    resetName() {
      this.name = "Reseted";
      this.$emit('resetNameParent',this.name);
    }
  }
}
</script>

```


---

# 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://xml-1.gitbook.io/vuejs/ep08-06-tuy-chinh-mot-su-kien-trong-component-con-and-and-ep08-08-viec-giao-thuc-qua-callback-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.
