1

My vue component like this :

<template>
    <section>
        ...
        <form-input id="total-sold" name="total-sold" :value="products.total_sold">Total Sold</form-input>
        <form-input id="created-at" type="date" name="created-at" :value="products.created_at">Created At</form-input>
    </section>
</template>

<script>
    export default {
        props: ['products'],
        mounted() {
            console.log(this.products.total_sold) // The result : 46
            console.log(this.products.created_at) // The result : 2018-02-26 09:03:03
        },
    }
</script>

My form-input component vue like this :

<template>
    <div class="form-group">
        <label :for="id" class="control-label" :class="classLabel"><slot></slot></label>
        <input :type="type" :name="name" :id="id" class="form-control" :placeholder="dataPlaceholder" :disabled="disabled" :value="value">
    </div>
</template>

<script>
    export default {
        name: "form-input",
        props: {
            'id': String,
            'name': String,
            'type': {
                type: String,
                default: 'text'
            },
            'disabled': String,
            'dataPlaceholder': {
                type: String,
                default() {
                    return this.$slots.default ? this.$slots.default[0].text : ''
                }
            },
            'value': {
                type: [String, Number]
            }
        },
        data(){
            return {
                classLabel: {'sr-only': !this.$slots.default}
            }
        }
    }
</script>

So on the my first component vue, it will call form-input component vue. I make the component like that. So later that component can be used repeatedly

If the component executed, the input text from total sold display data. The result is 46. But the input text from created at is not display data. Seems it because the type is date

How can I solve this problem?

1 Answer 1

3

<input type="date"> expects a value in the form of YYYY-MM-DD, see MDN <input type="date">. You are trying to give it a value of the wrong format: 2018-02-26 09:03:03 which includes a timestamp.

You will need to create a wrapper input component or try an <input> that supports a time timestamp like <input type="datetime-local"> which expects a value in the format: yyyy-MM-ddThh:mm.

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

5 Comments

Look at this : jsfiddle.net/kbQ9E/212. I try your answer. It display the datetime. But when I click the datetime, it not display the date pop up
@SuccessMan What browser are you using? And it's datetime-local not just datetime.
Firefex 58.0.2 (64-bit)
Look at this : jsfiddle.net/kbQ9E/224. I try only date. I equate the value with the format. But the value is not display when the code run
Seems I need you help again. Look at this : stackoverflow.com/questions/49004669/…

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.