首页 > 解决方案 > 使标题帖子可点击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 做到这一点

标签: vue.js

解决方案


您需要为您的帖子创建一个视图组件。并使 h6 标题标签成为路由器链接标签,将您带到帖子(或文章)详细信息页面。


推荐阅读