【问题标题】:Vue + Luxon - Format using Luxon FilterVue + Luxon - 使用 Luxon 过滤器进行格式化
【发布时间】:2021-05-20 07:39:29
【问题描述】:

我声明在我的 Vue 组件中使用 Luxon。我已经导入了这个库,它可以工作了。

我使用 Luxon 过滤器作为:

{{ "2020-10-05T14:48:00.000Z" | luxon }}

此语法适用于时间戳格式,但现在我想使用其他格式作为示例:

<div>
    <p>{{ "2020-10-02 10:00:00" | luxon }}</p>
</div>

我已经阅读了 npm packagelibrary 的官方文档,但我没有得到结果。

在渲染组件时显示此错误消息:

app.js:101907 [Vue 警告]:渲染错误:“无法解析”

我知道问题是字符串的格式,但我不知道如何更改输入格式的类型。在metode中的作用是:

this.$luxon("2020-10-05 22:36", {
    input: { format: "yyyy-MM-dd HH:mm", zone: "Asia/Tokyo" },
    output: "full",
})

但是我需要直接在渲染组件(html)中使用过滤器。我试过这个:

<template>
    <div>
        <p>{{ "2020-10-02 10:00:00",{
                                       input: { format: "yyyy-MM-dd HH:mm", zone: "Asia/Tokyo"}
                                    } | luxon }}</p>
    </div>
</template>

显然它不起作用......

谁能帮帮我?

谢谢!

【问题讨论】:

    标签: vue.js date format momentjs luxon


    【解决方案1】:

    看看Docssite 这个:

    <div>
        <p>{{ "2020-10-02 10:00:00" | luxon({ input: {format: "yyyy-MM-dd HH:mm"} } ) }}</p>
    </div>
    

    应该可以正常工作

    【讨论】:

    • 具体来说:{{ data.value | luxon({ input: { format: "yyyy-MM-dd HH:mm:ss" } }) }} 你的回答是语法错误;)
    猜你喜欢
    • 2021-07-28
    • 2022-08-19
    • 2021-08-30
    • 2021-01-13
    • 2021-01-11
    • 2021-07-05
    • 2021-10-12
    • 2021-08-13
    • 2021-12-12
    相关资源
    最近更新 更多