0
我在VueJS異步後與VueJS和愛可信
created() {
axios.get('/wp-json/wp/v2/users/' + portal.user.id + '?context=edit', {headers: {'X-WP-Nonce': portal.nonce}})
.then(response => {
this.user = response.data;
})
.catch(e => {
this.errors.push(e);
});
axios.get('/wp-json/wp/v2/categories')
.then(response => {
this.terms = response.data;
})
.catch(e => {
this.errors.push(e);
});
},
methods: {
createPost: function() {
let title = this.new_post_title;
let content = this.new_post_content;
let tags = this.new_post_tags;
let status = this.status;
let data = {
'title': title,
'content': content,
'status': status,
};
axios.post("/wp-json/wp/v2/posts/", data, {headers: {'X-WP-Nonce': portal.nonce}})
.then(response => {
console.log(response);
})
.catch(e => {
this.errors.push(e);
console.log(this.errors);
});
this.new_post_title = '';
this.new_post_content = '';
this.new_post_tags = '';
}
},
一切工作與請求的方法和創建的屬性,數據被髮布到WordPress的,當我做了刷新頁面,我得到的頁面頂部的新帖子應該是這樣。
但是,我該如何着手讓頁面在請求完成後異步加載新文章?
如果發佈的請求成功,那麼我只需將發佈的數據插入到帶'Vue'回調函數的Vue頁面中。 –
您能否詳細說明一些小代碼片段?我只用了一個月左右的Vue。 –
是的。哪個網址獲取帖子? ''/ WP-JSON/WP/V2/categories''? –