vue.js 错误-无法读取未定义的属性(阅读“get”)

798qvoo8  于 2023-06-06  发布在  Vue.js
关注(0)|答案(1)|浏览(325)

当我运行我的程序时,我得到以下错误:

Cannot read properties of undefined (reading 'get')
TypeError: Cannot read properties of undefined (reading 'get')
    at Proxy.mounted (webpack-internal:///./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/views/HdHistory.vue?vue&type=script&lang=js:563:29)
    at eval (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:2811:88)
    at callWithErrorHandling (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:296:18)
    at callWithAsyncErrorHandling (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:304:17)
    at hook.__weh.hook.__weh (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:2791:19)
    at flushPostFlushCbs (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:461:41)
    at flushJobs (webpack-internal:///./node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:499:5)

这是我的代码:

mounted() {
    Promise.all([
      this.$http.get('/api/v0/tickets/divisions')
        .then((response) => {
          this.customer.items = response.data;
        }),
      this.$http.get('/api/v0/hd/groups')
        .then((response) => {
          this.groups.items.push(...response.data);
          // by default select all
          if (this.groups.selected.length === 0) this.groups.selected = this.groups.items
        }),
    ])
      .then(() => {
        this.timeScaleSelected();
      })
      .catch((e) => {
        console.error(e);
      });
  },

有人有什么想法吗?
我正在尝试将我的程序从vue2升级到vue3。

odopli94

odopli941#

检查main.js中您要使用的全局变量。
Vue 2格式:

Vue.prototype.$http = new HTTPService();

Vue 3格式:

const app = createApp(RootComponent)

app.config.globalProperties.$http = new HTTPService();

相关问题