TimePicker-检索选择的实际值(小时和分钟)

问题描述 投票:0回答:1

由于vue.js论坛似乎已死并且无法收到松弛的确认电子邮件,因此将在此处发布我的问题。

我最近开始使用.vue进行编码,并且有一个问题。

使用时间选择器选择时间后,我想将hourminute放入变量中。 (一个或多个,尚不确定)现在,我得到这个“ Sun 1 31 31 Sun,07:25:00 GMT-0500(EST)

我以为我可以做到

console.log(this.hour);
console.log(this.minute);
console.log(this.hour + ":" + this.minute);

他的代码在这里https://play.nativescript.org/?template=play-vue&id=pFJlwX&v=4

<template>
    <Page>
        <ActionBar title="Time Picker" />
        <ScrollView>
            <StackLayout class="home-panel">

                <TimePicker v-model="yourTimeValue" @timeChange="onHour" :hour="8" :minute="currentMinute" minuteInterval="5" />
                <TextField v-model="textFieldValue" hint="Enter text..." @returnPress=" onHour" />

            </StackLayout>
        </ScrollView>
    </Page>
</template>

<script>
    export default {
        data() {
            return {
                currentMinute: new Date().getMinutes(),
                textFieldValue: ""
            };
        },
        methods: {
            // when you release your finger from the timepicker, you end up in this function
            onHour: function(args) {
                console.log(this.yourTimeValue);  // returns something like this Sun Dec 31 1899 07:25:00 GMT-0500 (EST)
                console.log(this.textFieldValue); // this return the text you wrote in the text field
            }
        }
    };
</script>

<style scoped>
    .home-panel {
        vertical-align: center;
        font-size: 20;
        margin: 15;
    }

    .description-label {
        margin-bottom: 15;
    }
</style>

谢谢

vue.js nativescript timepicker nativescript-vue
1个回答
0
投票

v模型只能包含一个值,因此它是包含时间(小时和分钟)的日期。

您始终可以从日期对象解析小时和分钟,

console.log(this.yourTimeValue.getHours() + ":" + this.yourTimeValue.getMinutes());
© www.soinside.com 2019 - 2024. All rights reserved.