vue.js - 使标题帖子可点击vue
问题描述
我正在使用 vue + laravel,我尝试像这样显示来自 api 的数据:
<div v-for="article in articles" :key="article.id" class="hieght">
<div class="NewArticle">
<h6 class="NewArticleTitle">{{ article.title.ar }}</h6>
</div>
<div>
<p class="NewArticleBody">{{ article.excerpt.ar }}</p>
</div>
</div>
脚本是:
<script>
export default {
data() {
return {
articles: []
}
},
created() {
this.axios
.get('http://localhost:8000/api/articles/')
.then(response => {
this.articles = response.data;
});
}
}
但是我希望在单击标题时打开帖子,我不知道如何使用 vue 做到这一点
解决方案
您需要为您的帖子创建一个视图组件。并使 h6 标题标签成为路由器链接标签,将您带到帖子(或文章)详细信息页面。
推荐阅读
- java - 使用 doThrow() 不会抛出像 doThrow(null, NullPointerException.class) 这样的异常
- mysql - 在离子段中获取动态数据时如何删除空列?
- pandas - 将日期和时间列转换为时间戳
- jmeter - 如何从 Json 中提取值,其中多个子对象为单位,并且只需要提取特定值
- reactjs - 尝试将 React JS new Date() 输出转换为 date-fns formatISO
- php - 带有日期时间/反序列化的 Symfony 序列化实体失败
- javascript - 在 Forge Dataviz API 上使用异步回调
- oracle-apex - 通过简单的动态操作禁用弹出 LOV 在 Apex 4.2 中有效,但在 Apex 19.1 中无效
- typescript - Prisma - 使用时仅返回子对象字段
- postgresql - 嵌套`declare...begin...end`中的%rowtype