2

I wanted to integrate Datetime picker with vue 2 or 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? Any help would be highly appreciated.

Thanks.

1

2 Answers 2

6

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.

There is the VueStrap project, but it works with Vue1, see their datepicker. This fork is supposed to support Vue2, but I can't ensure its quality. However it could gives you some inspiration about how to integrate your datepicker if you want to do it yourself, see the datepicker code.

If you don't mind using another datepicker, I would suggest some others that are trivial to integrate to your project:

Sign up to request clarification or add additional context in comments.

Comments

5

Here I'll be using the code from bootstrap's 3 example. You have to create a component for the 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>

3 Comments

I tried your code, now it showing me $(".datetime").datetimepicker() is not a function a function. Can you suggest me how to import datetimepicker as I am very new to Vue 2
You have to import the bootstrap's js somewhere in your code for example in your index/main .js or as CDN in index.html. This is more related to webpack specifics.
The above code seems to change the date but not the model value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.