我想在vue.js中渲染新组件,就像它是新页面一样。我试图用“动态组件”这样做parent:Post.vue child:Detail.vue因此,如果单击其中一个帖子,则关闭帖子并打开详细信息。问题是我必须将点击的帖子ID发送到详细信息。这是我的一些代码。Post.vue<template> <div> <div v-if="loading"> loading... </div> <div v-else class="container"> <ul> <li v-for="(post, index) in filteredPosts" v-bind:key="post.no"> <section class="post__main"> <div @click..?? class="main__title">{{post.title}}</div> </section> </li> </ul> </div> </div></template><script> created() { axios.get(this.url, { params: { page: this.page, ord: this.ord, category: [] } }).then(res => { this.posts = res.data.list; this.loading = false; this.page++; });Detail.vue<template> <div> {{contents}} </div></template><script>import axios from 'axios';export default { name: 'Datail', data() { return { req_no: null, contents: {} } }, created() { axios.get(url, { params: { req_no: this.req_no } }).then(res => { this.contents = this.res.data }); }}</script>我觉得我可以做到这一点props和v-if。有人能帮我吗?谢谢!
添加回答
举报
0/150
提交
取消
