简体   繁体   English

如何在Laravel中创建Vue js的新App.js?

[英]How to create new App.js of Vue js in Laravel?

I create a website with Laravel and Vue.js . 我用LaravelVue.js创建了一个网站。

I has created a public page for user. 我为用户创建了一个公共页面。 And now I want to create an admin page. 现在我想创建一个管理页面。 In the public page, I used app.js of Vue.js to manage that page. 在公共页面中,我使用了Vue.js app.js来管理该页面。 And now I want to manage admin page with Vue.js , too. 现在我想用Vue.js管理管理页面。

How can I do that? 我怎样才能做到这一点? I think I need to create a new app.js file to manage admin page? 我想我需要创建一个新的app.js文件来管理管理页面? It is right or wrong? 这是对还是错?

You dont need to create a new app.js for your admin page seperatly , instead you call the app.js which is the vuejs framework it self and make a new component or components for admin panel like below : 你不需要为你的管理页面单独创建一个新的app.js,而是你自己调用app.js这是vuejs框架,并为管理面板制作一个新的组件,如下所示:

<script src="{{asset('js/app.js')}}"></script>  //both in admin and public

and here 2 components in your 这里有2个组件

resource/js/components

name them like : 将它们命名为:

admin.vue

and

public.vue

write any thing in them like this : 像这样在里面写任何东西:

    <template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Example Component</div>

                    <div class="card-body">
                        I'm an example component.
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
    <script>
        export default {
            mounted() {
                console.log('Component mounted.')
            }
        }
    </script>

and now in your admin part you would write 现在在你的管理部分你会写

<admin></admin> // this will call the admin.vue component

and in your public the same 在你的公众中也一样

<public></public> //this will call the public.vue component

and last dont forget to register your components so in app.js do like this : 并且最后不要忘记注册你的组件,所以在app.js中这样做:

Vue.component('admin', require('./components/admin.vue').default);
Vue.component('public', require('./components/public.vue').default);

Hope This Helps. 希望这可以帮助。

EDIT as you said in comments that u need to work with vue.router here is what you can do : simple just install vue and add it like below : 编辑正如你在评论中所说,你需要在这里使用vue.router是你可以做的:简单的只需安装vue并添加如下:

    import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/admin'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'admin',
      component: admin
    }
  ]
})

and in your component you simply add the router : 在您的组件中,您只需添加路由器:

    <router-link :to="{ name: 'Hello' }">Home</router-link>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM