假设我有一个app.js
文件,我在其中注册每个组件并在laravel刀片文件中调用它。但是,并不是所有用户角色都需要所有组件。
这就是为什么我要拆分组件注册表。到不同的文件,然后根据角色调用该文件e。
我的app.js:
import Vue from "vue";
window.Vue = Vue;
window.axios = require("axios");
window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
require("promise.prototype.finally").shim();
import { Form, HasError, AlertError } from "vform";
window.Form = Form;
Vue.component(HasError.name, HasError);
Vue.component(AlertError.name, AlertError);
Vue.component("pagination", require("laravel-vue-pagination"));
import VueCtkDateTimePicker from 'vue-ctk-date-time-picker';
import 'vue-ctk-date-time-picker/dist/vue-ctk-date-time-picker.css';
Vue.component('VueCtkDateTimePicker', VueCtkDateTimePicker);
//sweet alert 2
import swal from "sweetalert2";
window.swal = swal;
const toast = swal.mixin({
toast: true,
position: "top-end",
showConfirmButton: false,
timer: 15000
});
window.toast = toast;
//vue lang
import VueInternationalization from "vue-i18n";
import Locale from "./vue-i18n-locales.generated";
Vue.use(VueInternationalization);
const lang = document.documentElement.lang.substr(0, 2);
// or however you determine your current app locale
const i18n = new VueInternationalization({
locale: lang,
messages: Locale
});
//vue lang end
//https://hamed-ehtesham.github.io/pretty-checkbox-vue/#installation
import PrettyCheckbox from "pretty-checkbox-vue";
Vue.use(PrettyCheckbox);
//vue autocomplete
//ckeditor
import CKEditor from "@ckeditor/ckeditor5-vue";
Vue.use(CKEditor);
/**
* Next, we will create a fresh Vue ap
*
*
* plication instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
// dash board
Vue.component(
"dashboard-site-latest-employee-attendance-list",
require("./components/dashboard/site/LatestEmployeeAttendanceComponent.vue")
);
Vue.component(
"dashboard-site-latest-student-attendance-list",
require("./components/dashboard/site/latestStudentAttendanceListComponent.vue")
);
Vue.component(
"dashboard-site-employee-attendance-graph",
require("./components/dashboard/site/dashboardEmployeeAttendanceGraphComponent.vue")
);
/* ====Global filter START =========================*/
Vue.filter("activeInactive", function(value) {
if (value == 1) {
return "Active";
} else {
return "Inactive";
}
});
const app = new Vue({
el: "#app",
i18n,
components: {},
methods: {},
mounted() {
console.log("d" + document.documentElement.lang.substr(0, 2));
}
});
,这里有100多个组件注册。 有什么方法可以制作不同的文件并将其捆绑在一起?
我的意思是这样的:
mix.js("resources/js/app.js", "public/js/vue")
.js("resources/js/administrator.js", "public/js/vue")
.js("resources/js/reseller.js", "public/js/vue")
.js("resources/js/user.js", "public/js/vue")
.sass("resources/sass/app.scss", "public/css")
是否有一个主app.js文件,其中可以导入和过滤公共库以及new Vue{()}
和组件reg。在不同的文件中?我将添加那些基于js的捆绑角色,将使用页面和组件。
这样,用户将不会被迫下载他不需要的所有js。现在,用户必须下载完整的js文件(产品上为6 Mb)。
答案 0 :(得分:-1)
您可以使用laravel刀片条件和类似的堆栈
@push('jsscripts')
@if($role === 'admin')
<script src='/js/admin.js>
@endif
@endpush