351070
复现仓库 下载后
$ npm i
$ npm run dev
分别在 http://localhost:8000/ 和 http://127.0.0.1:3101/ 进行访问
问题代码在 /services/base.js
import { request, config } from '@/utils'
export async function getI18n(lang) {
let path = '/i18n'
if (lang) {
path = `/i18n/${lang}`
}
console.log(`async function getI18n() lang = ${lang}`)
return request(`${config.api.base}/${encodeURIComponent(path)}`)
}
/services/base.js
class App extends Component {
state = { initDone: false };
componentDidMount() {
this.loadLocales();
}
loadLocales() {
const currentLocale = getCurrentLocale()
getI18n(currentLocale).then(res => {
// init method will load CLDR locale data according to currentLocale
intl.init({
currentLocale,
locales: {
[currentLocale]: res.data
}
})
}).then(() => {
// After loading CLDR locale data, start to render
this.setState({ initDone: true });
});
}
render() {
const { initDone } = this.state
const { children } = this.props
return (
initDone &&
<LocaleProvider locale={getLocale()}>
{ children }
</LocaleProvider>
);
}
}
export default App;
getI18n(currentLocale).then(res => { 这里在8000端正常,在3101端却 res 为空,请问是什么问题?
以上项目是模仿 egg-ant-design-pro 来做的