【问题标题】:vue-moment issue in laravel-inertialaravel-inertia 中的 vue-moment 问题
【发布时间】:2021-07-06 16:12:26
【问题描述】:

我尝试导入 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' });

This is the error i am getting

【问题讨论】:

    标签: laravel vue.js momentjs inertiajs


    【解决方案1】:

    首次安装时刻

    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>
    

    【讨论】:

    • 有了这个,我需要在任何我使用时刻正确的地方导入它。我正在尝试使其在全球范围内可用,但它在 vue3 的最新 laravel-inertia 中不起作用
    【解决方案2】:

    有一个如何从我的 Laravel +惯性项目中导入“vue-moment”的工作示例

    const vm = new Vue({
      metaInfo: {
        titleTemplate: title => (title ? `${title} - Ping CRM` : 'Ping CRM'),
      },
      store,
      render: h =>
        h(App, {
          props: {
            initialPage: JSON.parse(el.dataset.page),
            resolveComponent: name => import(`@/Pages/${name}`).then(module => module.default),
          },
        }),
    }).$mount(el)
    
    Vue.use(require('vue-moment'))
    

    【讨论】:

    • 好的,最新的 laravel-inertia 正在使用 vue3,我在那里遇到了这个错误。您发送的此代码有效。当然,我每次使用时都可以导入时刻。只是想弄清楚我的代码出了什么问题。
    猜你喜欢
    • 2021-05-04
    • 2021-05-03
    • 2021-07-06
    • 2022-11-12
    • 2021-10-24
    • 2021-03-30
    • 2022-06-10
    • 2021-06-20
    • 2020-02-19
    相关资源
    最近更新 更多