我正在嘗試使用帶有React.js的gmail API。React-只運行一次加載外部js文件的文件(gapi未定義)
我不斷收到錯誤'gapi未定義'。我相信我的client.js
文件中的HTML是我mail.js
文件運行後加載?
我該如何解決這個問題?
的Index.html
...
<script src="https://apis.google.com/js/client.js"></script>
Index.js
import './Mail.js';
在mail.js
import { createAction, handleActions } from 'redux-actions'
const CLIENT_ID = '1.apps.googleusercontent.com'
const SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
export const SET_GMAIL_CREDENTIALS = 'SET_GMAIL_CREDENTIALS'
export const CHANGE_LOADING = 'CHANGE_LOADING'
export const SET_GMAIL_LABELS = 'SET_GMAIL_LABELS'
export const SELECT_GMAIL_LABEL = 'SELECT_GMAIL_LABEL'
export const SET_GMAIL_EMAILS = 'SET_GMAIL_EMAILS'
let defaultState = {
profile: {
emailAddress: ''
},
loading: true,
labels: [],
currentLabel: null,
emails: []
}
export const connect =() => {
return (dispatch, getState) => {
dispatch(turnLoadingOn())
gmailAuth(false, populateCredentials(dispatch), clearCredentials(dispatch))
}
}...
是您的Gmail-API腳本標記您的捆綁反應/應用程序腳本標記之後? – Conan