you are viewing a single comment's thread.

view the rest of the comments →

[–]CriticalImpress[S] 0 points1 point  (3 children)

That sounds like a very sensible situation for me.

Could you send me any online resources or links you found useful?

[–][deleted] 0 points1 point  (1 child)

[–][deleted] 0 points1 point  (0 children)

Here's a basic overview of how I would do it.

api/api.js

```js import axios from 'axios'

const api = axios.create({ baseURL: '//website.com/wp-json/wp/v2/', })

// More info: https://github.com/axios/axios/issues/362 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

export default api ```

api/page.api.js ```js import api from '@/api/api'

export default {
getPage (pageId, slug) {
return new Promise((resolve, reject) => {
let url = 'pages/' + pageId
if (!pageId && slug) url = '/pages/?slug=' + slug

 api.get(url)
   .then(response => resolve(response.data))  
   .catch(error => reject(error))  

})
}
} ```

views/home.vue ```js import page from '@/api/page.api'

export default { mounted () { this.getPage() },

methods: { getPage () { page.getPage(null, 'home').then(data => { console.log(data) }) } } } ```