The react project is used to call Wechat's jssdk interface and report 'wx' is not defined no-undef'.

problem description

In the

react project, when configuration information is injected into pages that need to use JS-SDK, the console prints: "wx" is not defined no-undef
what to do?

the environmental background of the problems and what methods you have tried

1. There are
2 js files introducing Wechat into the index.html interface, http://res.wx.qq.com/open/js/., or
3, and changing the location of Wechat"s js in the index.html interface. The error message is still the same

related codes

Wechat"s js file is introduced into the index.html interface

<body>
    ...
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>
</body>

introduce configuration into other component interfaces

class Invite extends Component {

  render() {
    ...
    wx.config({
      debug: true,
      appId: "**********", 
      timestamp: *****, 
      nonceStr: "*****", 
      signature: "***",
      jsApiList: ["***", "***"]
    });
    return (<div>...</div>)
   }

what result do you expect? What is the error message actually seen?

how to solve this problem?

The

react component is shielded from global variables. Referencing global variables requires window


window.wx.config () to try.
jweixin.js needs to be introduced before your js .

Menu