【发布时间】:2017-12-19 07:37:18
【问题描述】:
我正在使用 laravel 5.4 和 vue 2.0。我需要插入像 facebook 这样的父帖子的 cmets。 我想将“帖子 ID”从父模板传递给子模板,以插入该父帖子的 cmets。
<div class="post-section" v-for="(post,index) in posts">
<div class="media-content" v-text='post.body'></div>
<button @click="getComments(post, index)" class="btn btn-link">Comments</button>
<div v-if='show' class="card comment" v-for='comment in post.comments'>
<span> {{comment.comment}}</span>
</div>
<comment-input :post="post.id" @completed='addRecentComment'></comment-input>
</div>
//评论输入模板
<template>
<form @submit.prevent='onSubmit'>
<div class="media-comment">
<input @keyup.enter="submit" type="text" v-model='form.comment' class="form-control" placeholder="comment...">
</div>
</form>
</template>
<script>
export default {
data() {
return {
form: new Form({comment: ''})
}
},
methods: {
onSubmit() {
this.form
.post('/comments')
.then(post => this.$emit('completed', comment));
}
}
}
</script>
提前致谢!!
【问题讨论】:
-
那么你的问题到底是什么?
-
我想将帖子 id 从父组件传递给子组件(注释输入),以将 id 彻底的 axios 请求发送到我的控制器。现在我无法将帖子 ID 从父组件发送到子组件。
标签: javascript php vuejs2 laravel-5.4 vue-component