How do you implement two-way data binding in a Vue.js component?


Posted On: Jan 02, 2023


To implement two-way data binding in a Vue.js component, you can use the "v-model" directive. This directive binds a value to a form input element, and updates the value whenever the input element's value changes.

Here is an example of how you might use the "v-model" directive in a Vue.js component:

   <input v-model="message" type="text">
   <p>{{ message }}</p>

export default {
  data() {
    return {
      message: 'Hello world!'

In this example, the value of the "message" data property is bound to the value of the input element using the "v-model" directive. When the user types in the input element, the value of the "message" data property is updated, and this change is reflected in the text displayed by the p element.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Vue.js Interview Questions

    What is Vue.js?

    Vue js is progressive javascript script used to create dynamic user interfaces.Vue js is very easy to learn.In order to..

    Vue.js Interview Questions

    List some features of Vue.js.

    Vue js comes with following features Templates Reactivity Components Transitions Routing ..

    Vue.js Interview Questions

    Explain Life cycle of Vue Instance.

    The Life cycle of each Vue instance goes through a series of initialization steps when it is created. – for example, ..