【发布时间】:2018-05-15 17:50:36
【问题描述】:
我能够使用 axios 和 Vue.js 显示 WordPress 帖子内容。一旦我切换到按 slug 过滤,我就无法显示帖子内容。
<template>
<div>
<article>
<h2 class="subtitle">{{ post.title.rendered }}</h2>
<div v-html="post.excerpt.rendered"></div>
</article>
</div>
</template>
<script>
import axios from "axios";
import Router from 'vue-router'
export default {
name: 'ShowPost',
data () {
return {
post: []
}
},
created() {
this.slug = this.$route.params.slug;
},
mounted() {
axios({ method: "GET", "url": "https://wpdemo.stevensoehl.com/wp-json/wp/v2/posts?slug=" + this.slug }).then(json => {
this.post = json.data;
}, error => {
console.error(error);
});
}
}
</script>
【问题讨论】:
-
我在你的 api url 中使用了邮递员,并且能够使用 slug 返回 hello-world。是否可能 this.slug 以某种方式被解析,因此不再匹配?尝试制作更多测试帖子,看看是否有任何回复
-
在调试控制台查看网络面板,url是什么?
-
Daniel-我检查了网络面板,响应选项卡显示基于 url 的正确响应,但未显示帖子内容。使用帖子ID时显示帖子内容