Vue Typescript Flatpickr this。$ refs.field不可分配给'string'类型的参数

时间:2019-04-04 15:05:20

标签: typescript vue.js flatpickr

Typescript中的{p> Vue,其中FlatpickrVeevalidate作为数据包。

错误线this.fp = new Flatpickr(this.$refs.field, {})

  

错误:“元素|类型”的参数元素[] | Vue | Vue []'不可分配给'string'类型的参数。     不能将“元素”类型分配给“字符串”类型。

<template>
  <div>
    <label :for="name">{{ name }}</label>
     <input
      v-validate="validation"
      :name="name"
      :id="name"
      v-model="name"
      :placeholder="name"
      ref="field"
      type="text"
      value="value"
      @input="$emit('input', $event.target.value)"
    >
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import Flatpickr from 'flatpickr'

@Component({})
export default class BaseDate extends Vue {
  @Prop()
  name!: string

  @Prop({ default: '' })
  validation!: string

  @Prop()
  model!: string

  @Prop()
  validator!: any

  fp: any

  mounted (): void {
    this.$validator = this.validator
    this.fp = new Flatpickr(this.$refs.field, {})
  }
}
</script>

2 个答案:

答案 0 :(得分:1)

只需将参数强制转换为CREATE table copy_emp(eid, ename,job,mid,sal,dept_id, constraint emp_pk primary key (eid)) as SELECT employee_id, concat(first_name,last_name),job_id,manager_id,salary,department_id FROM employees; (或Element):

Node

this.fp = new Flatpickr(this.$refs.field as Element, {}) 构造函数期望参数为Flatpickr类型的参数。 TypeScript无法将Node | Node[] | string类型转换为预期的类型;

$refs

答案 1 :(得分:0)

这是对我有效的最终解决方案:

this.fp = new (Flatpickr as any)(this.$refs.field as Element, {})