【问题标题】:Vue & TypeScript How to get the data property in render?Vue 和 TypeScript 如何在渲染中获取数据属性?
【发布时间】:2019-01-26 03:37:30
【问题描述】:

当我使用 TypeScript 时,我试图在渲染中使用它。 但它无法运行:

TS2339:类型上不存在属性“选项” '组件选项,默认方法, DefaultComputed, PropsDefinition

import Vue from 'vue'

declare module 'vue/types/vue' {
    interface Vue {
        onSwtich: Function
    }
}

export default Vue.extend({
    name: 'footerTabs',
    data() {
        return {
            options: {
                on: {
                    click: el => this.onSwtich(el)
                }
            }
        }
    },
    render(h) {
        return h('swiper', {
            class: 'page-footer-tabs',
            attrs: {
                options: this.options  // TS2339: Property 'options' does not exist on type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Rec...'.
            }
        })
    },
    methods: {
        onSwtich(el): void {
            this.$emit('on-switch', el)
        }
    }
})

我已经尝试添加选项

界面 Vue { 选项:对象 }

还是不行

【问题讨论】:

    标签: typescript vue.js


    【解决方案1】:
    declare module 'vue/types/options' {
        interface ComponentOptions<V extends Vue> {
            options?: any
        }
    }
    

    原来需要这样声明。

    【讨论】:

      猜你喜欢
      • 2021-12-03
      • 2020-02-11
      • 2021-05-10
      • 2019-02-08
      • 2019-07-30
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多