gpt4 book ai didi

vuejs2 - 如何在 Vue.js 组件中使用矩库

转载 作者:行者123 更新时间:2023-12-03 22:53:51 27 4
gpt4 key购买 nike

之后,yarn add moment
我试过...

import moment from 'moment'
Vue.prototype.moment = moment

&
import moment from 'moment'
Vue.use(moment)

&
var moment = require('moment');
Vue.use(moment)

没有什么是真正有效的。我收到各种奇怪的错误消息!

谁能告诉,如何在 Vue.js 2 中使用矩库?

最佳答案

最后,它起作用了!

调用 moment()从组件内部 methods堵塞。

示例用法:-

<template>
<v-ons-page>
<p>{{isToday("12-02-1980")}}</p>
</v-ons-page>
</template>

<script>
import moment from 'moment'

export default {
methods: {
isToday(date) {
return moment(date).isSame(moment().clone().startOf('day'), 'd');
},
}
}
</script>

关于vuejs2 - 如何在 Vue.js 组件中使用矩库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45609012/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com