Javascript 将vuejs组件注册拆分到不同的文件
假设我有一个Javascript 将vuejs组件注册拆分到不同的文件,javascript,vue.js,webpack,laravel-mix,Javascript,Vue.js,Webpack,Laravel Mix,假设我有一个app.js文件,我在其中注册每个组件,并在LaravelBlade文件中调用它。但并非所有用户角色都需要所有组件。 这就是为什么我要拆分我的组件注册表。到不同的文件,并根据角色调用该文件e。 我的app.js: import Vue from "vue"; window.Vue = Vue; window.axios = require("axios"); window.axios.defaults.headers.common["X-Requested-With"] = "XM
app.js
文件,我在其中注册每个组件,并在LaravelBlade文件中调用它。但并非所有用户角色都需要所有组件。
这就是为什么我要拆分我的组件注册表。到不同的文件,并根据角色调用该文件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{()}
和组件注册。在不同的文件中?我将添加那些捆绑的基于js的角色,这些角色将使用页面和组件。
这样用户就不会被迫下载他不需要的所有js。现在,用户必须下载完整的js文件(prod上为6MB)。您可以使用laravel刀片条件和堆栈,如
@push('jsscripts')
@if($role === 'admin')
<script src='/js/admin.js>
@endif
@endpush
@push('jsscripts')
@如果($role==='admin')
您可以使用laravel刀片条件和堆栈,如
@push('jsscripts')
@if($role === 'admin')
<script src='/js/admin.js>
@endif
@endpush
@push('jsscripts')
@如果($role==='admin')
我的问题与刀片无关。当我将app.js文件吐到多个文件时,它会给出错误!组件未找到。您可以为每个组件创建一个js文件,并仅导入所需的组件。我的问题与刀片无关。当我将app.js文件吐到多个文件时,它会给出错误!组件未找到。您可以为每个组件创建一个js文件,并仅导入所需的组件。