【问题标题】:TimePicker - retrieving actual values selected (hour and minute)TimePicker - 检索选择的实际值(小时和分钟)
【发布时间】:2019-12-22 20:20:31
【问题描述】:

将在这里发布我的问题,因为 vue.js 论坛似乎已经死了并且无法收到松弛确认电子邮件。

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

使用 timepicker 选择时间后,我想将 hourminute 放入一个变量中。 (一个或多个,还不确定) 现在我得到这个“Sun Dec 31 1899 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】:

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

    你总是可以从日期对象中解析小时和分钟,

    console.log(this.yourTimeValue.getHours() + ":" + this.yourTimeValue.getMinutes());
    

    【讨论】:

    • 非常感谢!我能够将它集成到我的其余代码中并让一些东西正常工作!我很感激。我将继续阅读有关 v-model 和 .vue 的信息。另外,如果我看这里nativescript-vue.org/en/docs/elements/components/time-picker 我怎么知道我必须使用“getHours”和“getMinutes”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-25
    • 2021-11-19
    • 1970-01-01
    相关资源
    最近更新 更多