react-app中引入moment

版权声明:前端菜鸟--人间草木所有 https://blog.csdn.net/qq_43258252/article/details/87858912

首先你要确保react环境搭建成功

第一步:

npm 安装moment ,文件根目录下安装,指令如下

npm install moment -save    //安装到生产环境

第二步:

在src/index.js 中引入 moment 插件

方便你复制~~~

import moment from 'moment'

React.Component.prototype.$moment = moment

第三步:

在组件中使用moment转换数据

方便你复制~~~

    let time = this.$moment(this.state.time).format('YYYY-MM-DD HH:mm:ss')
    console.log(time)

猜你喜欢

转载自blog.csdn.net/qq_43258252/article/details/87858912