我正在使用NuxtJS 2.12.2版。我正在尝试在异步提取中访问$moment
,但它返回的 app.$moment
不是函数。以下是我的代码段:
页面/_key.vue
<template>
<div></div>
</template>
<script>
import { mdSign } from '@/constants/encryption.js'
var pickerValue = new Date()
var dTime = pickerValue.getTime()
export default {
async fetch({ store, params, app }) {
const theUuid = app.$generateUUID() // this is a global property
const theSignature = mdSign({
uuid: theUuid
})
const body = {
cpKey: params.key,
day: app.$moment(pickerValue).format('YYYY-MM-DD'),
sign: theSignature,
time: dTime
}
await store.dispatch('example/fetchHistory', body)
}
}
</script>
<style lang="scss" scoped></style>
plugins / filter.js
import Vue from 'vue'
import { translations } from '@/constants/pinyin.js'
const moment = require('moment')
Vue.use(require('vue-moment'), {
moment
})
nuxt.config.js
export default {
...
...
plugins: [
'~/plugins/filters.js',
...
...
]
...
...
答案 0 :(得分:1)
将@ nuxtjs / moment添加到您的项目中:
npm i @nuxtjs/moment
在您的nuxt.config.js模块中添加@ nuxtjs / moment:
modules: [
'@nuxtjs/moment'
]
您通常会在Vue应用程序中使用的许多库都有Nuxtjs特定的软件包。