首页 > 解决方案 > 未处理的拒绝(TypeError):无法读取未定义的属性“销毁”

问题描述

反应 / JS 菜鸟在这里。我收到以下错误 - “未处理的拒绝(TypeError):无法读取未定义的属性'destroy'”尝试运行以下 -

import React from 'react';

const { Client } = require('tplink-smarthome-api');

let client = new Client()

const plug = client.getDevice({host: '192.168.1.10'}).then((device)=>{
  device.getSysInfo().then(console.log);
  device.setPowerState(true);
});

我试过使用异步函数,比如——

const toggle = async () => {
const plug =  await client.getPlug({ host: '192.168.1.10' })
plug.setPowerState(true)
}

上面的代码在 plug.setPowerState(true) 之前一直有效。这会导致“未处理的拒绝(TypeError):无法读取未定义的属性'destroy'”。这在 node.js 中运行良好,但是一旦我尝试将 react 加入混合中,什么都没有。谢谢 - 我已经尝试了好几天了。

标签: javascriptreactjs

解决方案


推荐阅读