Vue.js 在NuxtJS的异步获取中访问$moment
我使用的是NuxtJS 2.12.2版。。我试图在异步获取中访问Vue.js 在NuxtJS的异步获取中访问$moment,vue.js,nuxt.js,Vue.js,Nuxt.js,我使用的是NuxtJS 2.12.2版。。我试图在异步获取中访问$moment,但它返回应用程序。$moment不是函数。以下是我的片段: 页面/_key.vue <template> <div></div> </template> <script> import { mdSign } from '@/constants/encryption.js' var pickerValue = new Date() var dTime
$moment
,但它返回应用程序。$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>
numxt.config.js
import Vue from 'vue'
import { translations } from '@/constants/pinyin.js'
const moment = require('moment')
Vue.use(require('vue-moment'), {
moment
})
export default {
...
...
plugins: [
'~/plugins/filters.js',
...
...
]
...
...
将@nuxtjs/moment添加到您的项目中:
npm i @nuxtjs/moment
将@nuxtjs/moment添加到您的nuxt.config.js模块:
modules: [
'@nuxtjs/moment'
]
Vue应用程序中通常使用的许多库都有特定于Nuxtjs的软件包。我觉得似乎存在名称不匹配的问题。当您在nuxt配置中编写
plugins/filters.js
时,您的文件是plugins/filter.js
。这也可能是一个复制错误,但我看不出你的代码有任何其他错误。你试过了吗?@DeanChristianArmada使用安装方法将其作为一个新插件安装,你可以从任何地方轻松访问它