0

Ошибка собственно в методе Vue компонента: метод UI компонента

Использую дефолтный Nuxt + TypeScript, в @types есть 2 файла:

vue-shim.d.ts

declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}

tsx-shim.d.ts

import Vue, { VNode } from 'vue';

declare global {
  namespace JSX {
    interface Element extends VNode {}
    interface ElementClass extends Vue {}
    interface IntrinsicElements {
      [element: string]: any;
    }
  }
}
1
  • тайпскрипт не знает что именно будет лежать в $ref, поэтому проверяет, чтобы указанный метод был во всех типах из union.
    – Grundy
    12 мая 2021 в 11:07

1 ответ 1

0
import Vue, { VueConstructor, VNode} from 'vue'

interface Refs {
  $refs: {
    list: HTMLElement,
    input: HTMLInputElement,
  }
}

export default (Vue as VueConstructor<Vue & Refs>).extend({
  ...
  methods: {
    dropdownTrigger (e: Event | undefined) {
      this.$refs.list.scrollTo(0, 0) // наконец то отлично отрабатывает
    }
  }
  ...
})

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.