首页 > 解决方案 > laravel-inertia 中的 vue-moment 问题

问题描述

我尝试导入 vue-moment 并使用 .use(VueMoment) 对其进行初始化,如下所示。但是在我这样做之后,整个应用程序都会显示错误。有人面临同样的问题吗?

    require('./bootstrap');

// Import modules...
import { createApp, h } from 'vue';
import { App as InertiaApp, plugin as InertiaPlugin } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import VueMoment from 'vue-moment' ////////imported vue-moment

const el = document.getElementById('app');

createApp({
    render: () =>
        h(InertiaApp, {
            initialPage: JSON.parse(el.dataset.page),
            resolveComponent: (name) => require(`./Pages/${name}`).default,
        }),
})
    .mixin({
        methods: {
            route,
            validationError(field){
                if(this.$page.props.errors && this.$page.props.errors[field]){
                    return this.$page.props.errors[field];
                }
                else{
                    return null;
                }
            }
    } })
    .use(InertiaPlugin)
    .use(VueMoment) /////use vue-moment
    .mount(el);

InertiaProgress.init({ color: '#4B5563' });

这是我得到的错误

标签: laravelvue.jsmomentjsinertiajs

解决方案


第一次安装时刻

npm install moment

<template>
{{today}}
</template>
<script>
import   moment from 'moment'
export default {
 name:'Home',
 data(){
  return{
  today:moment().startOf('day').toDate(), moment().endOf('day').toDate() 
}
}
</script>

推荐阅读