npm TypeErrror:尝试使用Flatpickr插件时,monthSelectPlugin不是构造函数

9ceoxa92  于 2022-11-14  发布在  其他
关注(0)|答案(2)|浏览(162)

我尝试在rails应用程序中使用monthSelectPlugin for flatpickr。我将它固定在我的导入Map中,如下所示:

pin "flatpickr/dist/plugins/monthSelect", to: "https://cdn.jsdelivr.net/npm/flatpickr@4.6.13/dist/plugins/monthSelect/index.js"

我在一个刺激控制器中使用它,使用他们文档中的示例:

import { Controller } from "@hotwired/stimulus"
import flatpickr from "flatpickr"
import * as monthSelectPlugin from 'flatpickr/dist/plugins/monthSelect';
export default class extends Controller {
  static targets = ['picker']
  connect() {
    const picker_div = this.pickerTargets;
    
    flatpickr(picker_div, {
      plugins: [
        new monthSelectPlugin({
          shorthand: true, //defaults to false
          dateFormat: "m.y", //defaults to "F Y"
          altFormat: "F Y", //defaults to "F Y"
          theme: "dark" // defaults to "light"
        })
    ]});
  }
}

但尝试此操作会导致错误:

TypeError: monthSelectPlugin is not a constructor

花了足够长的时间才真正把这个正确地进口,有人明白这里出了什么问题吗?

gj3fmq9x

gj3fmq9x1#

改为导入monthSelect

import monthSelect from 'flatpickr/dist/plugins/monthSelect';
watbbzwu

watbbzwu2#

导入Map更改到

pin "flatpickr/dist/plugins/monthSelect", to: "https://ga.jspm.io/npm:flatpickr@4.6.13/dist/plugins/monthSelect/index.js"

输入

import monthSelectPlugin from "flatpickr/dist/plugins/monthSelect"

相关问题