2

How to create interface or class and create object and assign the template values to object and print it on console?

<template> 
<input type="text" id="name" v-model="name" placeholder="name">
<input type="email" id="email" v-model="email" placeholder="email">
</template>
@Component({

})
export default class example extends Vue({
   data(
       return {
              name: '',
              email: '',
      }}
})
2
  • Have you tried using watchers? Commented Feb 13, 2020 at 7:42
  • Using v-model should automatically bind the input values on the data object properties. Commented Feb 13, 2020 at 7:48

1 Answer 1

2

v-model should automatically bind the input values on the data object properties.

To print the value on the console when changed, you can use vue watchers.

Because you are using class components, you can use the vue-property-decorator package to create watchers.

import { Component, Watch } from 'vue-property-decorator'

@Component
export default class example extends Vue {
  name = ''
  email = ''

  @Watch('name')
  onNameChanged(val: string, oldVal: string) {
    console.log('name': val)
  }

  @Watch('email')
  onEmailChanged(val: string, oldVal: string) {
    console.log('email': val)
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.