Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问在taro中怎么使用 #250

Open
xian107 opened this issue Apr 13, 2024 · 2 comments
Open

请问在taro中怎么使用 #250

xian107 opened this issue Apr 13, 2024 · 2 comments

Comments

@xian107
Copy link

xian107 commented Apr 13, 2024

image
image
加了localeDone会报错,去掉localeDone国际化又不起作用,强制重渲染APP组件都没用

@cwtuan
Copy link
Collaborator

cwtuan commented Apr 16, 2024

show more code

@xian107
Copy link
Author

xian107 commented Apr 16, 2024

show more code
@cwtuan
image
image
把{localeDone ? children : null}改成 {children} 不会报错了,但是国家化失效了,需要relaunch访问到其他页面再切回来才有效。
`import { Provider } from "react-redux";
import intl from "react-intl-universal";
import Taro from "@tarojs/taro";
import { useEffect, useState } from "react";
import { store } from "./store";

function App({ children }: any): any {
const [localeDone, setLocaleDone] = useState(false);
useEffect(() => {
Taro.request({
url: "get url api", // 异步获取json文件
success(res: any = {}) {
if (res.statusCode === 200 && res.url) {
Taro.request({
url: res.url,
success(result: any = {}) {
console.log("返回json", result.data);
if (result.statusCode === 200 && result.data) {
intl
.init({
currentLocale: "en-US",
locales: {
"en-US": result.data.EN,
"zh-CN": result.data.CH,
},
})
.then(() => {
setLocaleDone(true);
});
}
},
});
}
},
});
}, []);
return {localeDone ? children : null};
}
export default App;`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants