V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
coolair
V2EX  ›  微信

请问下 dayjs 怎么在微信小程序的 wxml 页面里面使用?

  •  
  •   coolair · 2022-07-13 11:09:31 +08:00 · 959 次点击
    这是一个创建于 624 天前的主题,其中的信息可能已经有所发展或是发生改变。
    现在是在 js 里面转好,有没有办法直接在 wxml 里面使用?
    7 条回复    2022-07-25 16:59:29 +08:00
    zcf0508
        1
    zcf0508  
       2022-07-13 11:18:19 +08:00
    在 methods 里把 dayjs 相关的方法暴露出去就可以了
    magewu1223ll
        2
    magewu1223ll  
       2022-07-13 11:22:33 +08:00
    把包下下来 放进你的项目里
    coolair
        3
    coolair  
    OP
       2022-07-13 11:27:51 +08:00
    @zcf0508 老哥,怎么操作的,直接在 js 里面暴露然后再 wxml 里面调用?

    <tag value="{{ dayjs(mydatetime).format('YYYY-MM-DD HH:mm:ss') }}" />

    像上面这样写,没有效果啊。
    zcf0508
        4
    zcf0508  
       2022-07-13 13:22:48 +08:00
    methods:{
    dayjsformat(datetime,format):{
    return dayjs(datetime).format(format)
    }
    }
    coolair
        5
    coolair  
    OP
       2022-07-13 15:00:11 +08:00
    @zcf0508 老哥,没有用啊,用法是我上面写的那样吗?
    zcf0508
        6
    zcf0508  
       2022-07-13 17:44:26 +08:00
    @coolair <tag :value="{{ dayjsformat(mydatetime,'YYYY-MM-DD HH:mm:ss') }}" />
    coolair
        7
    coolair  
    OP
       2022-07-25 16:59:29 +08:00
    @zcf0508 老哥,测试了没用啊,原生小程序不能这么写吧,你这是 Vue 的写法吧?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5006 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 09:47 · PVG 17:47 · LAX 02:47 · JFK 05:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.