Search code examples
javascriptvuejs3

Passing form data to setup() featuring form input binding Vue js 3


im new at vue js ,so i have a litle bit confusing problem in vue js 3. what i try to do is passing the data to setup() which i got from the form using v-model(form input binding). after I read the official documentation, setup cant access the data component so i have no idea how to solve this problem. It would be helpful if you would give me a hint for this problem.

<template>
<textarea name="inputName" id="inputName" class="form-control" v-model.lazy="inputName"></textarea>
</template>

<script>
import { ref } from "vue";
export default {
    setup() { 
      function request(){ // give the data to this method
      }
    },
    data(){
        return{
            inputName //trying to pass this data to setup()
        }
    }
    mounted() {
        console.log('Component mounted.')

    },  
}

Solution

  • You can’t pass data from data() to setup(), setup method firing way before data(). don’t use composition api for now, no problems with that.

    So if you want submit something just create function inside methods(), and take your data like this: this.inputName