抱歉,這個問題會有點模糊,主要是因為我真的不知道下一步該去哪里。我在這里學習了本教程(https://auth0.com/blog/how-to-make-secure-http-requests-with-vue-and-express/),一切都運行到幾乎最后一個條目。現在,我收到這些錯誤:
ERROR in /home/aron/code/cx/client/src/views/EventSingle.vue(44,10):
44:10 Property 'getEventData' does not exist on type '{ name: string; data(): { event: {}; }; created(): void; methods: { getEventData(): Promise<void>; }; }'.
42 | },
43 | created() {
> 44 | this.getEventData(); // NEW - call getEventData() when the instance is created
| ^
45 | },
46 | methods: {
47 | async getEventData() {
ERROR in /home/aron/code/cx/client/src/views/EventSingle.vue(49,36):
49:36 Property '$auth' does not exist on type '{ getEventData(): Promise<void>; }'.
47 | async getEventData() {
48 | // Get the access token from the auth wrapper
> 49 | const accessToken = await this.$auth.getTokenSilently()
| ^
50 |
51 | // Use the eventService to call the getEventSingle method
52 | EventService.getEventSingle(this.$route.params.id, accessToken)
ERROR in /home/aron/code/cx/client/src/views/EventSingle.vue(52,38):
52:38 Property '$route' does not exist on type '{ getEventData(): Promise<void>; }'.
50 |
51 | // Use the eventService to call the getEventSingle method
> 52 | EventService.getEventSingle(this.$route.params.id, accessToken)
| ^
53 | .then(
54 | (event => {
55 | this.$set(this, "event", event);
ERROR in /home/aron/code/cx/client/src/views/EventSingle.vue(55,14):
55:14 Property '$set' does not exist on type '{ getEventData(): Promise<void>; }'.
53 | .then(
54 | (event => {
> 55 | this.$set(this, "event", event);
| ^
56 | }).bind(this)
57 | );
58 | }
這是我的 tsconfig.json:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
"noImplicitAny": false,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"sourceMap": true,
"baseUrl": ".",
"resolveJsonModule": true,
"types": [
"webpack-env",
"jest"
],
"typeRoots": ["./@types", "./node_modules/@types"],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost","es2015", "es2016", "es2018.promise"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
我對 TypeScript、Javascript 等并不十分熟悉,我一直在尋找各種方法來解決這個問題 - https://blog.risingstack.com/auth0-vue-typescript-quickstart-docs/和https: //auth0.com/docs/quickstart/spa/vuejs/01-login。
我的猜測是 Vue 物件原型沒有使用 Auth0 插件進行擴展,這與撰寫本教程以來框架發生的變化有關。有什么建議?如果有幫助,很高興粘貼更多資訊。
謝謝!
uj5u.com熱心網友回復:
要在單個檔案組件中啟用型別推斷,請Vue.extend()在組件宣告中使用:
// EventSingle.vue (Vue 2)
import Vue from 'vue';
??
export default Vue.extend({
created() {
this.getEventData(); // ?? type inference now enabled
}
})
在 Vue 3 中,defineComponent()改為使用:
// EventSingle.vue (Vue 3)
import{ defineComponent } from 'vue';
??
export default defineComponent({
created() {
this.getEventData(); // ?? type inference now enabled
}
})
uj5u.com熱心網友回復:
第一個錯誤報告清楚地告訴您,getEventData在this. 此外,根據您所遵循的指南,this.getEventData是為了呼叫this.methods.getEventData,因此是問題。我認為您所遵循的指南中存在一些錯誤。
關于其他錯誤,tony19 回答了它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/368937.html
標籤:javascript 打字稿 Vue.js Vuejs2
