我尝试在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
花了足够长的时间才真正把这个正确地进口,有人明白这里出了什么问题吗?
2条答案
按热度按时间gj3fmq9x1#
改为导入
monthSelect
:watbbzwu2#
导入Map更改到
输入