0

I need some enlightenment. Right now, I'm learning vue.js, and I want to know how to take all data value from input form?? I want take all data from there & save into my database. But, I still don't know, how to get all these data.. thx

<div id="example-1">
        <form>
            <input v-model="info.name">
            <input v-model="info.nickname">
            <input v-model="info.gender">
            <input type="submit" name="" value="Submit" v-on:click="submitData">
        </form>
    </div>

    <script>
        var example1 = new Vue({
                el: '#example-1',
                data: {
                    info: {
                        name: '',
                        nickname: '',
                        gender: ''
                    }
                }
            },
            methods: {
                submitData: function() {
                    console.log(this.info);
                    // this.$http.post('/api/something', JSON.stringify(this.info));
                }
            })
    </script>
3
  • The commented out line in the submitData function will post the data to a URL. You need to have a back end service at that URL the can read the posted data and put it into your database. Commented Mar 8, 2017 at 17:41
  • i already have back end to handle this, but i just want to know, how to get all these data from input from. Thx Commented Mar 8, 2017 at 17:44
  • The back end should receive the stringified this.info that should contain all the form data. Commented Mar 8, 2017 at 19:52

1 Answer 1

1

I bet you need to prevent the default action. When you submit a form, the page automatically reloads. You won't ever see a response from the server in the console because it will clear when the page refreshes after the submission action.

Go here, and ctrl + f 'Event Modifiers'. You'll want to use .prevent in this case, then write your own code to handle the submission / response.

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.