如何将Vuex添加到我的Laravel Nova工具中?

问题描述 投票:-1回答:1

我想在我的自定义Laravel Nova工具中使用Vuex。如何以一种干净的方式实现这一目标?

php laravel vuex laravel-nova
1个回答
0
投票

[我发现Nova已经在使用Vuex,您可以将自己的Vuex商店模块添加到现有商店。

此内容未在文档中进行介绍,因此我不知道在新版本中是否可以继续使用,但在Nova 1.3中似乎可以解决问题。

您可以像这样将Vuex模块注册到nova-components / MyTool / resources / js / tool.js:

import datastore from './store/datastore'


Nova.booting((Vue, router, store) => {
    store.registerModule(
        'mynamespace/datastore', datastore
    );

    // router.addRoutes( ......


});

并且您可以像这样在Tool.vue中使用它:

<template>
    <div>
      {{ testing }}
    </div>
</template>

<script>
    import {mapGetters} from 'vuex'
    export default {
        mounted() {
        },
        computed: {
            ...mapGetters({
                testing: 'mynamespace/datastore/testing'
            })
        }
    }
<script>

Nova正在将所有资源添加到同一存储中,因此您必须使用命名空间存储来避免冲突。

我希望这可以节省您一些时间。

© www.soinside.com 2019 - 2024. All rights reserved.