javascript - How to use a flatpickr with a vue component? - Stack Overflow

Disclaimer: I'm new to vue.jsIm need help to get a date picker working with my modal ponents. I ha

Disclaimer: I'm new to vue.js

Im need help to get a date picker working with my modal ponents. I have made the modal and that workers fine, I've also installed a date picker ('flatpickr') and that works fine when I call it on an element not within a ponent.

However when I try to use it on the modal nothing happens. Im unsure where I should be calling the date picker within the ponent as I thought you should refrain from putting anything with side effects as they won't me parsed.

Im unsure where is should be including the flatpickr script, should it be within the template or should it be in my main app.js.

My modal ponent.vue

<template>
<div class="cis-modal is-active">
 <div class="cis-modal-background">
    <div class="cis-modal-content animated bounceInUp">
        <div class="card">
            <div class="card-body">

                <slot></slot>

            </div>
        </div>
    </div>
    <button class="cis-modal-close" @click="$emit('closed')"><i class="fa fa-times" aria-hidden="true"></i></button>
</div>
</div>

<script>
 export default {
 }
</script>

The flatpickr script

<script>
 $("#talentDOB").flatpickr({
 enableTime: true,
 dateFormat: "F, d Y H:i"
});

The modal being called

<modal v-if="showEditTalentModal" @closed="showEditTalentModal = false;">
{!! Form::model($talent, ['method' => 'PATCH', 'action' =>     ['TalentController@update', $talent->user_id], 'files'=>true ]) !!}

<div class="form-group">
  {!! Form::label('dob', 'Date of Birth:') !!}
  {!! Form::text('dob', null, [ 'data-input','class'=>'form-control',  'required' => 'required', 'id' => 'talentDOB']) !!}
</div>

<div class="form-group">
 {!! Form::submit('Update Profile', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</modal>

Thank you in advanced.

Disclaimer: I'm new to vue.js

Im need help to get a date picker working with my modal ponents. I have made the modal and that workers fine, I've also installed a date picker ('flatpickr') and that works fine when I call it on an element not within a ponent.

However when I try to use it on the modal nothing happens. Im unsure where I should be calling the date picker within the ponent as I thought you should refrain from putting anything with side effects as they won't me parsed.

Im unsure where is should be including the flatpickr script, should it be within the template or should it be in my main app.js.

My modal ponent.vue

<template>
<div class="cis-modal is-active">
 <div class="cis-modal-background">
    <div class="cis-modal-content animated bounceInUp">
        <div class="card">
            <div class="card-body">

                <slot></slot>

            </div>
        </div>
    </div>
    <button class="cis-modal-close" @click="$emit('closed')"><i class="fa fa-times" aria-hidden="true"></i></button>
</div>
</div>

<script>
 export default {
 }
</script>

The flatpickr script

<script>
 $("#talentDOB").flatpickr({
 enableTime: true,
 dateFormat: "F, d Y H:i"
});

The modal being called

<modal v-if="showEditTalentModal" @closed="showEditTalentModal = false;">
{!! Form::model($talent, ['method' => 'PATCH', 'action' =>     ['TalentController@update', $talent->user_id], 'files'=>true ]) !!}

<div class="form-group">
  {!! Form::label('dob', 'Date of Birth:') !!}
  {!! Form::text('dob', null, [ 'data-input','class'=>'form-control',  'required' => 'required', 'id' => 'talentDOB']) !!}
</div>

<div class="form-group">
 {!! Form::submit('Update Profile', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</modal>

Thank you in advanced.

Share Improve this question asked Apr 7, 2018 at 19:23 Gregg RedmanGregg Redman 551 silver badge7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

First, import the ponent.

import flatpickr from 'flatpickr'

Then create the flatpicker instance in mounted

flatpickr('#datepicker')

Of course you need to have an input with the same id

<input type="text" id="datepicker" v-model="dateValue" autoplete="off"/>

Actually there is no any special requirements yo use it in Vue.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744583962a4582201.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信