未定義不是對象的對象反應天然-未定義不是(評價「_reactNative.CookieManager.get」)(評價「_reactNative.CookieManager.get」)
undefined is not an object (evaluating '_reactNative.CookieManager.get')
這個錯誤是在機器人仿真示出。 在react.js
CookieManager.get("http://10.42.0.1:8000/login/", (err, res) => {
fetch("http://10.42.0.1:8000/login/", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRFToken': res.csrftoken,
},
body: JSON.stringify({
username: 'user',
password: 'securepassword',
})
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
});
}
pacakge.json
"dependencies": {
"babel-preset-react-native": "2.1.0",
"react": "16.0.0-alpha.12",
"react-native": "0.47.1",
"react-native-cookie": "^0.2.0",
"react-navigation": "^1.0.0-beta.11"
},
"devDependencies": {
"babel-jest": "20.0.3",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
},
我已經一步一步完成的: -
從NPM安裝庫
npm install react-native-cookie --save
鏈路本地代碼
react-native link react-native-cookie
在這裏app.js
import {
Cookie,
CookieManager
} from 'react-native-cookie';
任何建議都歡迎進口。我們是吸請幫忙擺脫這個!
鏈接'react-native-cookie'後,您是否使用'react-native run-android'進行重建?在開發的本地端修改任何內容後,重載(R,R)將不會執行。只刷新'Javascript'。 – MattyK14
@ MattyK14是的。絕對重建整個項目。仍然看起來是錯誤的。 –
看起來'react-native-cookie'中沒有CookieManager導出。只有Cookie被導出,並且它有get方法:https://github.com/shimohq/react-native-cookie#get – ligaz