code
import logo from './logo.svg';
import './App.css';
import React from 'react';
import axios from 'axios'
import { ContentApiClient, HaloRestAPIClient } from "@halo-dev/content-api";
// 创建 halo http 请求客户端
const haloRestApiClient = new HaloRestAPIClient({
baseUrl: 'http://127.0.0.1:8090',
auth: { apiAccessKey: 'halo-dev-test' },
});
// 通过 http 客户端创建 halo 前台 api 客户端
const haloContentClient = new ContentApiClient(haloRestApiClient);
class App extends React.Component{
componentDidMount(){
//
axios.get('http://127.0.0.1:8090/api/content/archives/months',{
params: {
api_access_key: 'halo-dev-test'
}
}).then((res)=>{
console.log(res);
})
// 获取文章列表
haloContentClient.post.list().then((res) => {
console.log(res);
});
}
render(){
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
}
export default App;