繁体   English   中英

如何在 vue.js 上制作 post 方法?

[英]How do I make the post method on vue.js?

你好。 我开始学习 vue.js 并制作了一个表格,我想将其发送到 API。 我将代码留在这里,我尝试使用 post 方法,但它没有反应。 就像它什么也没做一样。 所以也许你可以帮助我知道我的代码有什么问题,因为我很绝望:非常感谢:)

<template>
   <div class= "form" >
        <form name= "form" method="post">
            <div id="data">
                <h3 class="index">tell us about you</h3>
                <div id="row">
                    <div id="first">
                        <label class="input">Name</label>
                        <input v-model="name" type="text" name="name" class="control" placeholder="">
                    </div>
                    <div id="first">
                        <label class="input">Description about you</label>
                        <p><textarea class="control" v-model="description" name="description"                         placeholder=""></textarea></p>
                    </div>
                </div>
                <div id="row">
                    <div id="second">
                        <label class="input">Age</label>
                        <input type="text" name="category" v-model="age" class="control" placeholder="">

                        </select>
                    </div> 
                    <div id="button">
                        <a v-on:click="sendInfo()" class="btn">Upload</a>
                    </div>
            </div>
        </form>
   </div>
</template>


<script>
import axios from 'axios';
export default {
    name: 'sendinfo',
    data(){
        return{
            name: '',
            description: '',
            age:'',

        }
    },
    methods:{

        sendInfo(){

            axios.post("https://jsonplaceholder.typicode.com/posts", {
                name: this.name,
                description: this.description,
                age: this.age,
            }).then((result) => {
                console.log(result);
            });
            }

        }
        }



</script>

你好。 我开始学习 vue.js 并制作了一个表格,我想将其发送到 API。 我将代码留在这里,我尝试使用 post 方法,但它没有反应。 就像它什么也没做一样。 所以也许你可以帮助我知道我的代码有什么问题,因为我很绝望:非常感谢:)

<template>
   <div class= "form" >
        <form name= "form" method="post">
            <div id="data">
                <h3 class="index">tell us about you</h3>
                <div id="row">
                    <div id="first">
                        <label class="input">Name</label>
                        <input v-model="name" type="text" name="name" class="control" placeholder="">
                    </div>
                    <div id="first">
                        <label class="input">Description about you</label>
                        <p><textarea class="control" v-model="description" name="description"                         placeholder=""></textarea></p>
                    </div>
                </div>
                <div id="row">
                    <div id="second">
                        <label class="input">Age</label>
                        <input type="text" name="category" v-model="age" class="control" placeholder="">

                        </select>
                    </div> 
                    <div id="button">
                        <a v-on:click="sendInfo()" class="btn">Upload</a>
                    </div>
            </div>
        </form>
   </div>
</template>


<script>
import axios from 'axios';
export default {
    name: 'sendinfo',
    data(){
        return{
            name: '',
            description: '',
            age:'',

        }
    },
    methods:{

        sendInfo(){

            axios.post("https://jsonplaceholder.typicode.com/posts", {
                name: this.name,
                description: this.description,
                age: this.age,
            }).then((result) => {
                console.log(result);
            });
            }

        }
        }



</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM