Import a Vue js component from Laravel Blade File

前端 未结 3 1622
甜味超标
甜味超标 2021-02-04 22:39

I have registered a some components as a global components in js/app.js file, But this makes the compiled app.js file larger.

//example         


        
3条回答
  •  野的像风
    2021-02-04 23:06

    register the component in another file rather than app.js

    resources/js/example.js

    window.Vue = require('vue');
    Vue.component('example-component', require('./components/ExampleComponent.vue').default);
    

    Compile your component to another file in webpack.mix.js

    mix.js('resources/js/app.js', 'public/js')
       .js('resources/js/example.js', 'public/js')
       .sass('resources/sass/app.scss', 'public/css');
    

    Include it in blade

    
    

提交回复
热议问题