wordpress vue
您的Vue和WordPress权威指南-第1部分 (Your Definitive Guide to Vue and WordPress — Part 1)
I am currently working on a freelance project that involves retrieving posts from a WordPress site and displaying them on a custom dashboard and an Android and iOS app. It has been a fun project so far and I thought I would share my experience working with the WordPress REST API and Vue. I’ll publish another article about the mobile app experience soon! I will also go over how to create new posts from a Vue app in a separate article.
我目前正在从事一个自由职业项目,该项目涉及从WordPress网站检索帖子并将其显示在自定义仪表板以及Android和iOS应用上。 到目前为止,这是一个有趣的项目,我想分享一下使用WordPress REST API和Vue的经验。 我将很快发布另一篇有关移动应用程序体验的文章! 我还将在另一篇文章中介绍如何从Vue应用创建新帖子。
如何使用WordPress Rest API检索帖子 (How to Retrieve Posts Using the WordPress Rest API)
To read data from the WordPress site, we will use an API already built into the WordPress site. The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects. To successfully use this API, there are a few things to know.
要从WordPress网站读取数据,我们将使用WordPress网站中已内置的API。 WordPress REST API通过发送和接收作为JSON (JavaScript对象符号)对象的数据为应用程序与WordPress站点进行交互提供了接口。 要成功使用此API,需要了解以下几点。
我的API端点在哪里? (Where are my API Endpoints?y)
For a full list of endpoints for the WordPress REST API, check out the link below.
有关WordPress REST API端点的完整列表,请查看下面的链接。
REST API Developer Endpoint Reference
To read data from your WordPress site, you must know where to request it. To get posts from your WordPress site, you would use the following endpoint.
要从WordPress网站读取数据,您必须知道在何处请求数据。 要从您的WordPress网站获取帖子,您可以使用以下端点。
YourWebSite/wp-json/wp/v2/posts
YourWebSite / wp-json / wp / v2 / posts
For this article, we will use the sample site provided in the WordPress Rest API documentation.
对于本文,我们将使用WordPress Rest API文档中提供的示例站点。
To retrieve posts from the site linked above, your endpoint would look like the example below:
要从上面链接的站点检索帖子,您的端点应类似于以下示例:
https://demo.wp-api.org/wp-json/wp/v2/posts
https://demo.wp-api.org/wp-json/wp/v2/posts
The above endpoint returns a JSON object representing posts from the demo WordPress site. If you click on the link, you w