Php WordPressAPI:如何使用laravel上的vue js按类别获取帖子
我构建了一个cms系统,前端使用laravel和vue js,后端使用wp rest api。所以我把新闻分类作为一篇文章,我只希望新闻分类出现在我的页面上,怎么做,因为现在我从所有分类中得到所有的文章?有没有可能,这是我的vue js代码来获取所有帖子Php WordPressAPI:如何使用laravel上的vue js按类别获取帖子,php,json,wordpress,laravel,vue.js,Php,Json,Wordpress,Laravel,Vue.js,我构建了一个cms系统,前端使用laravel和vue js,后端使用wp rest api。所以我把新闻分类作为一篇文章,我只希望新闻分类出现在我的页面上,怎么做,因为现在我从所有分类中得到所有的文章?有没有可能,这是我的vue js代码来获取所有帖子 <script> import sanitizeHtml from 'sanitize-html' export default { created(){ axios.get('http://loca
<script>
import sanitizeHtml from 'sanitize-html'
export default {
created(){
axios.get('http://localhost/newlara/main/public/wp/wp-json/wp/v2/posts?per_page=9')
.then(response => {
//console.log(response);
this.posts = response.data
})
},
data(){
return{
posts: []
}
},
methods: {
stripTags(html) {
return sanitizeHtml(html, {
allowedTags: []
}).substring(0, html.indexOf('…'))
}
}
};
</script>
从“清理html”导入sanitizeHtml
导出默认值{
创建(){
axios.get()http://localhost/newlara/main/public/wp/wp-json/wp/v2/posts?per_page=9')
。然后(响应=>{
//控制台日志(响应);
this.posts=response.data
})
},
数据(){
返回{
员额:[]
}
},
方法:{
stripTags(html){
返回sanitizeHtml(html{
allowedTags:[]
}).substring(0,html.indexOf('&hellip;'))
}
}
};
希望你能帮助我,谢谢。你可以通过
http://demo.wp-api.org/wp-json/wp/v2/categories/<id>
http://demo.wp-api.org/wp-json/wp/v2/categories/
请查看此处的文档
您想从后端加载所有帖子并在前端拆分它们吗?我想从我用wordpress制作的类别加载帖子,我有新闻类别。从我的代码现在我可以从wordpress后端加载我的所有帖子