admin管理员组文章数量:1221309
I have a list of items (taken from a JSON file) which I currently loop through, however I wish to create a details page for each of these items (incorporating VueRouter).
Any pointers on how to achieve this? I'm currently stuck on passing the data to the details page template.
Thanks
<ul>
<li v-for="projects in projects.projects">
{{ projects.name }}
<router-link :to="profileLink" class="button is-outlined">View Details</router-link>
{{ projects.coding }}
{ projects.design }}
{{ projects.description }}
</li>
</ul>
I have a list of items (taken from a JSON file) which I currently loop through, however I wish to create a details page for each of these items (incorporating VueRouter).
Any pointers on how to achieve this? I'm currently stuck on passing the data to the details page template.
Thanks
<ul>
<li v-for="projects in projects.projects">
{{ projects.name }}
<router-link :to="profileLink" class="button is-outlined">View Details</router-link>
{{ projects.coding }}
{ projects.design }}
{{ projects.description }}
</li>
</ul>
Share
Improve this question
edited Mar 20, 2017 at 15:46
Stephen K
asked Mar 20, 2017 at 12:47
Stephen KStephen K
1891 gold badge1 silver badge8 bronze badges
1 Answer
Reset to default 18See those links :
- https://router.vuejs.org/en/essentials/dynamic-matching.html
- https://router.vuejs.org/en/essentials/named-routes.html
With your use case what you could do is:
set up a new named route called details:
{ path: '/project/:projectId/details', name: 'details', component: Details, props: true, }
Every time you want to redirect a user to details page, use this route. The :projectId means it's dynamic, you can provide any id, it will always redirect to the component Details you created to display a project's details.
Create a new router link in your list like so:
<router-link :to="{ name: 'details', params: { projectId: project.id }}">{{project.name}}</router-link>
Inside your component details, you have to declare route params as props, for instance
props: ["id"],
. You can then access it in your component with this.id.
本文标签: javascriptVueJSVue Routercreate details page from list itemStack Overflow
版权声明:本文标题:javascript - VueJSVue Router - create details page from list item? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739361981a2159863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论