通过 POST axios vue 传递多个参数

Wah*_*ief 2 javascript laravel-5 axios vuejs2

我正在尝试使用 axios 将 props 值和表单值传递给后端控制器。但它只发送表单值而不是道具值。我的代码是 -

<template>
    <form @submit.prevent='onSubmit'>
        <div class="media-comment">
            <input type="text" v-model='form.comment' class="form-control" placeholder="comment...">
        </div>
    </form>
</template>

<script>
    export default {
        props: ['postId'],

        data() {
            return {
                form: new Form({comment: ''}),
                id: this.postId
            }
        },

        methods: {
            onSubmit() {
                console.log(this.postId); // it shows the value in console but the value doesnt pass
                this.form
                    .post('comments', this.data)
                    .then(post => this.$emit('completed', comment));
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

在控制台中,它只显示评论,而不显示道具值:

在此处输入图片说明

如何传递两个值?

提前致谢

Wah*_*ief 6

在这里我得到了解决方案。

<template>
    <form @submit.prevent='onSubmit'>
        <div class="media-comment">
            <input type="text" v-model='comment' class="form-control" placeholder="comment...">
        </div>
    </form>
</template>

<script>
    export default {
        props: ['postId'],

        data() {
            return {
                comment: ''
            }
        },

        methods: {
            onSubmit() {
                axios.post('comments', {comment: this.comment, id: this.postId})
                    .then(post => this.$emit('completed', comment));
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)