# react 数据没有更新

//状态
const [houseName,setHouseName] = useState()    //更新页面,重新渲染


//数据请求
const okHideModal = () => {
    setVisible(false);
    let signature = getSingature(timestamp, nonce, accountcode, SignToken, "");
    let headers = { accountcode, timestamp, nonce, signature };
    const res = http.post(`/api/project/ChangeBuildName?buildId=${changeBuildNum}&buildName=${houseName}`, null, headers);
    res.then((res) => {
        setHouseName(...houseName)   //-->展开,即可更新视图;
        message.success(res.data.Data)
    })
};

useEffect(() => {
    console.log(houseName,'effect11')
    axios({
        method: "get",
        url: "/api/account/GetToken",
        params: {
            accountCode: accountcode,
        },
        headers: { timestamp, nonce },
    })
        .then((res) => {
        sessionStorage.setItem("SignToken", res.data.Data.SignToken);
        const SignToken = res.data.Data.SignToken;
        let signature = getSingature(timestamp, nonce, accountcode, SignToken, "");
        axios({
            method: "get",
            url: "/api/project/GetBuildInfoByAccount",
            headers: {  accountcode,  timestamp, nonce,  signature},
        }).then((res) => {
            setAlldata(res.data.Data);
            // message.success(res.data.Data)
        });
    })
        .catch(function (error) {});
}, [uploadStatus,houseName,updater]);  // houseName依赖



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
上次更新: 9/1/2022, 17:19:28