javascript 为什么我得到了一个错误在我的handleClick异步函数?

bt1cpqcv  于 2023-02-11  发布在  Java
关注(0)|答案(1)|浏览(217)

我尝试将display_1和diplay_2添加到我的突变变量中,并尝试将其记录到console.log中,但console.log(数据、加载、错误)的输出为(未定义、错误、未定义)

const CREATE_T09_SCREENSHOT = gql`
  mutation 
    createT09ScreenShot(  
      $screenshot_window_1: String!, 
      $screenshot_window_2: String!,  
    ) { 
    createT09ScreenShot(
       screenshot_window_1: $screenshot_window_1, 
       screenshot_window_2: $screenshot_window_2, 
    ) { 
       screenshot_window_1
       screenshot_window_2
      } 
    }
`;
const SaveLogsButton = () => {
  const [createT09ScreenShot, { loading, error, data }] = useMutation(CREATE_T09_SCREENSHOT);
  
  const handleClick = async () => {
    const screenshotData = await saveImage();
    if (screenshotData){
    const { display_1, display_2 } = screenshotData;
    createT09ScreenShot({
      variables: {
        screenshot_window_1: display_1,
        screenshot_window_2: display_2,
      },
    });
  }
    console.log(data)
    console.log(loading)
    console.log(error)
  };

我也尝试这样做,但它给予了我一个错误

const handleClick = async () => {
    await saveImageFunction();
    const { display_1, display_2 } = saveImage;
    createT09ScreenShot({
      variables: {

这就是错误

Unhandled Promise Rejection: TypeError: Right side of assignment cannot be destructured
wrrgggsh

wrrgggsh1#

我认为您在saveImage destructurable对象的handleclick函数内部有一些错误。
您需要将handleClick函数代码替换为以下代码:

const handleClick = async () => {
    const screenshotData = await saveImageFunction();
    const { display_1, display_2 } = screenshotData;
    createT09ScreenShot({
      variables: {
        screenshot_window_1: display_1,
        screenshot_window_2: display_2,
      },
    });
};

相关问题