【问题标题】:Vue Prop Decorator - Invalid prop type checkVue Prop Decorator - 无效的道具类型检查
【发布时间】:2020-11-02 19:35:42
【问题描述】:

我正在使用 vue-prop-decorator 和 Quasar 框架。 我有一个组件,我在其中收到一个道具,定义如下:

<FabricanteComponente   
                :fabricante="fabricante"
/>

在组件本身中,prop 是用装饰器来描述的:

 @Prop({
        default: () => new Fabricante()
    })
    fabricante: Fabricante;

从 package.json 库的最新更新中,我开始收到以下错误:

[Vue 警告]:无效的道具:道具“fabricante”的类型检查失败。预期,得到对象

关于 package.json 上列出的相关依赖项我有

    "quasar": "^1.12.11",
    "vue-class-component": "^7.2.3",
    "vue-property-decorator": "^9.0.0"
    "@types/node": "^14.0.22",
    "@typescript-eslint/eslint-plugin": "^3.6.0",
    "@typescript-eslint/parser": "^3.6.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-loader": "^4.0.2",
    "eslint-plugin-cypress": "^2.11.1",
    "eslint-plugin-vue": "^6.2.2",
    "ts-loader": "^8.0.0",
    "typescript": "^3.9.6",
    "vuex-module-decorators": "^0.17.0"

但我不知道错误在哪里。关于如何解决的任何想法?

【问题讨论】:

    标签: vue.js quasar vue-property-decorator


    【解决方案1】:

    今天我发现了问题。 Vue 本身并没有过多解释警告消息中发生的事情。

    尽管如此,正如您在 Prop 定义中看到的那样,它需要一个 Fabricante 实例,而我只是从请求中发送了一个原始对象。创建一个类,如

    .then((response)=> new Fabricante(response));
    

    解决了。

    【讨论】:

      猜你喜欢
      • 2021-03-18
      • 2017-07-31
      • 1970-01-01
      • 2019-02-27
      • 2021-09-15
      • 2023-01-10
      • 2021-11-07
      • 2018-12-15
      • 1970-01-01
      相关资源
      最近更新 更多