Vuejs typescript this.$refs..value does not exist

前端 未结 7 1478
野的像风
野的像风 2020-11-30 13:33

While rewriting my VueJs project in typescript, I came across a TypeScript error.

This is a part of the component that has a custom v-model.

An input field i

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 14:08

    In case of custom component method call,

    we can typecast that component name, so it's easy to refer to that method.

    e.g.

    (this.$refs.annotator as AnnotatorComponent).saveObjects();
    

    where AnnotatorComponent is class based vue component as below.

    @Component
    export default class AnnotatorComponent extends Vue {
        public saveObjects() {
            // Custom code
        }
    }
    

提交回复
热议问题