【问题标题】:VUE3 + IONIC - Property 'foo' does not exist on type '{ bar(): any; }'VUE3 + IONIC - 类型 '{ bar(): any; 上不存在属性 'foo' }'
【发布时间】:2021-08-08 17:19:51
【问题描述】:

我在 vue3 + ionic 上有一个错误,我尝试制作一个组件以使用 computed 获取图像并从 props 获取变量。这是我的代码

主页.vue

<MenuIcon name="subscribe" fileName="subscribe.png" />

MyComponent.vue

export default { 
  name: 'MenuIcon',
  props: {
    name: String,
    fileName: String
  },
  computed: {
    iconPath(): any{     
      return require('../../public/assets/icon/icon menu/'+this.fileName)
    }
  }
}

我尝试将我的fileName 属性更改为Object 并将我的iconPath 属性类型更改为字符串或函数,但仍然出错。请帮忙

感谢之前

【问题讨论】:

    标签: vue.js vue-component ionic4 vuejs3


    【解决方案1】:

    我认为您的代码没有问题,但奇怪的是,当您使用 ionic + vue + ts 和 export default {} 时,this.filename 没有错误

    您可以尝试添加defineComponent 看看是否有帮助?

    import { defineComponent } from "vue";
    
    export default defineComponent({
      name: "MenuIcon",
      props: {
        name: String,
        fileName: String,
      },
      computed: {
        iconPath(): any {
          return require("../public/assets/icon/" + this.fileName);
        },
      },
    })
    

    【讨论】:

    • 这很奇怪,我尝试了你之前的建议,但仍然出错,然后我重新启动我的电脑,它就可以工作了。谢谢人
    猜你喜欢
    • 2021-02-08
    • 2021-07-09
    • 2019-09-20
    • 2018-09-09
    • 2019-12-31
    • 2022-12-17
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多