我正在嘗試將這個庫安裝https://github.com/vue-gapi/vue-gapi/tree/releases/v1到我的 vue2 專案中,所以我只是按照頁面要求我做的事情去做。所以運行后npm install --save vue-gapi我添加了
import Vue from 'vue'
import VueGapi from 'vue-gapi'
Vue.config.productionTip = false
Vue.use(VueGapi, {
apiKey: 'myapikey',
clientId: 'myclientid.apps.googleusercontent.com',
discoveryDocs: ['https://sheets.googleapis.com/$discovery/rest?version=v4'],
scope: 'https://www.googleapis.com/auth/spreadsheets',
})
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
但我會收到這個錯誤
vue-gapi.common.js?8dd9:478 Uncaught TypeError: Cannot set properties of undefined (setting '$gapi')
at Object.install (vue-gapi.common.js?8dd9:478)
at Function.Vue.use (vue.esm.js?efeb:5130)
at eval (main.js?1c90:18)
at Object../src/main.js (app.js:2230)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at Object.0 (app.js:2247)
at __webpack_require__ (app.js:679)
at app.js:725
at app.js:728
進一步單擊Object.install (vue-gapi.common.js?8dd9:478)將顯示此錯誤

uj5u.com熱心網友回復:
可以看到vue-gapi.common.js包含Vue 3的代碼,可能是因為安裝了最新版本,導致報錯。
考慮到1.x支持Vue 2,應該是:
npm install --save vue-gapi@1
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/354911.html
上一篇:VueJs影像未顯示
