我是Vuejs的新手,我尝试使用axios简单获取WP Rest Api。我正在尝试获取帖子总数并显示该数字。我知道如何使用jQuery:
$.get( 'localhost/wp-json/wp/v2/posts', function( data, status, request )
{
numPosts = request.getResponseHeader('x-wp-total');
console.log( numPosts );
});
如何使用axios做到这一点?我这样尝试。
new Vue({
el: '#app',
data: {
total: []
},
mounted() {
axios.get("localhost/wp-json/wp/v2/posts")
.then(response => {this.total = response.headers('x-wp-total').total})
}
});
并输出:
<div id="app">
<p>
{{total}}
</p>
</div>
有人可以帮我吗?