简体   繁体   English

使用带有Vuejs 2的bootstrap-datetime选择器

[英]Using bootstrap-datetime picker with Vuejs 2

I wanted to integrate Datetime picker with vue 2 or webpack. 我想将Datetime选择器与vue 2或webpack集成。 I tried searching but couldn't find related article. 我试过搜索但找不到相关的文章。 Have anyone integrated the Datetime picker with Vue2 or webpack, is there any sample code available for reference? 有没有人将Datetime选择器与Vue2或webpack集成,是否有可供参考的示例代码? Any help would be highly appreciated. 任何帮助将受到高度赞赏。

Thanks. 谢谢。

You can sure find some issues on the subject by just Googling vuejs bootstrap datetimepicker , but honestly I'm not sure VueJS is well tailored to work with Bootstrap, that already have its own (jQuery) logic. 你可以通过Googling vuejs bootstrap datetimepicker找到关于这个问题的一些问题,但说实话,我不确定VueJS是否适合使用Bootstrap,它已经拥有自己的(jQuery)逻辑。

There is the VueStrap project, but it works with Vue1, see their datepicker . VueStrap项目,但它适用于Vue1,请参阅他们的日期选择器 This fork is supposed to support Vue2, but I can't ensure its quality. 这个分支应该支持Vue2,但我不能确保它的质量。 However it could gives you some inspiration about how to integrate your datepicker if you want to do it yourself, see the datepicker code . 但是,如果您想自己动手,它可以为您提供有关如何集成日期选择器的一些灵感,请参阅datepicker代码

If you don't mind using another datepicker, I would suggest some others that are trivial to integrate to your project: 如果您不介意使用其他日期选择器,我会建议其他一些非常简单的集成到您的项目:

Here I'll be using the code from bootstrap's 3 example . 在这里,我将使用bootstrap的3个示例中的代码。 You have to create a component for the datepicker: 您必须为datepicker创建一个组件:

Vue.component('datetimepicker', {
    template: `
            <div class='input-group date' ref="datetimepicker">
                <input type='text' class="form-control" :value="value" @change="update($event)" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
    `,
    props: ['value'],
    methods: {
        update(event){

            this.$emit('input', event.target.value);
        }
    },
    mounted(){
        $(this.$refs.datetimepicker).datetimepicker()
    }
});

And now you can use this component like this: 现在你可以像这样使用这个组件:

<datetimepicker v-model="myDate"></datetimepicker>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM