Moment import moment import moment import moment import moment import moment import moment import moment import moment import moment import moment import moment You can use NUXTL plugins to refer to global references directly. The specific implementation method is as follows:
1. Install the Moment packagempn i moment
In 2.nuxt.config.js
In the configuration fileplugins
Add to options:
plugins: [
'@/plugins/moments'
...
]
Copy the code
3. Create a new file under the plugins foldermoments.js
The content of the document is as follows:
Import Vue from 'Vue' import moment from 'moment' import 'moment/locale/zh-cn moment.locale('zh-cn') Vue.prototype.$moment = momentCopy the code
My project uses THE UI of ANTD Vue, so I wrote it together. If you also use the UI framework, you can write it together. My reference is as follows:
Import Vue from 'Vue' import Antd from 'ant-design-vue/lib' // import 'ant-design-vue/dist/antd. CSS 'import Locale ('zh-cn') Vue. Prototype.$moment = moment Vue.use(Antd)Copy the code
4. Use in Vue components
$moment(). Format (‘ YYYY-MM-dd ‘)