Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

vue js how to copy value from textbox to div

i am trying to run function when button is clicked.

and text box one value should display in div

Template code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<input v-model="textdata" type="text" class="w-full rounded">

<div class="bg-white h-10 w-full  ">{{textdata}}</div>

<button @click="getvalue" class="bg-green-800  rounded " >RECEIVE</button>

VUSJS:

<script>
import { defineComponent } from 'vue'

export default defineComponent({
  setup() {

function getvalue(){
    console.log(this.textdata)
    }

return{
    getvalue,
}

}

 
})
</script>

Right now it’s showing data in console, but how can i show same data on div.

>Solution :

You should define 2 refs and then update one of them from the other upon the click event

<script>
import { defineComponent, ref } from 'vue'

export default defineComponent({
  setup() {
    const textarea = ref("");
    const text = ref("");

    function getvalue(){
      this.text = this.textarea
    }

    return{
        getvalue,
        text,
        textarea,
    }
  }

})
</script>

<template>
  <input v-model="textarea" type="text" class="w-full rounded">
  <div class="bg-white h-10 w-full">{{text}}</div>

  <button @click="getvalue" class="bg-green-800  rounded " >RECEIVE</button>
</template>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading