我已将 jquery 和 jStorage 安装为npm i --save jstorage
(https://www.npmjs.com/package/jstorage)和npm i --save jQuery
. 我正在尝试使用 jStorage 并设置值,但出现错误:-
TypeError: Cannot read property 'set' of undefined
应用程序.js
import $ from 'jquery';
const App = props => {
const swithHandle = (function () {
console.log('hi'); // correct output
// localStorage.setItem('rememberMe', '323232dd'); // correct output
$.jStorage.set("mykey", "keyvalue"); //TypeError: Cannot read property 'set' of undefined
}());
return (
<BrowserRouter>
<div className="App" onClick={swithHandle()}>
<Navbar />
</div>
</BrowserRouter>
);
}