Javascript 如何在Vue.js中正确包含来自购买主题的脚本
最近,我从Themeforest(Keen)购买了theme,并试图在Vue.js应用程序中包含来自theme的脚本,但这些脚本会抛出错误 我尝试使用App.vue模板中的“import”导入这些脚本,尝试通过public.html中的script标记包含脚本,尝试通过document.createElement('script')将脚本包含在main.js中。jQuery有一个问题,但我通过npm安装并包含在main.js中修复了这个问题,所以引导脚本实际上可以工作 有一些错误,脚本会抛出:Javascript 如何在Vue.js中正确包含来自购买主题的脚本,javascript,vuejs2,vue-cli-3,Javascript,Vuejs2,Vue Cli 3,最近,我从Themeforest(Keen)购买了theme,并试图在Vue.js应用程序中包含来自theme的脚本,但这些脚本会抛出错误 我尝试使用App.vue模板中的“import”导入这些脚本,尝试通过public.html中的script标记包含脚本,尝试通过document.createElement('script')将脚本包含在main.js中。jQuery有一个问题,但我通过npm安装并包含在main.js中修复了这个问题,所以引导脚本实际上可以工作 有一些错误,脚本会抛出:
app.bundle.js:4 Uncaught ReferenceError: KTUtil is not defined
at app.bundle.js:4
at app.bundle.js:66
jquery.js?1157:3850 Uncaught TypeError: Cannot read property 'initMediumChart' of undefined
at mediumCharts (dashboard.js:11)
at Object.init (dashboard.js:952)
at HTMLDocument.<anonymous> (dashboard.js:972)
at mightThrow (jquery.js?1157:3557)
at process (jquery.js?1157:3625)
fullcalendar.bundle.js:1327 Uncaught TypeError: Cannot read property 'fn' of undefined
at Object.<anonymous> (fullcalendar.bundle.js:1327)
at __webpack_require__ (fullcalendar.bundle.js:35)
at Object.<anonymous> (fullcalendar.bundle.js:4820)
at __webpack_require__ (fullcalendar.bundle.js:35)
at Object.<anonymous> (fullcalendar.bundle.js:2045)
at __webpack_require__ (fullcalendar.bundle.js:35)
at Object.<anonymous> (fullcalendar.bundle.js:14373)
at __webpack_require__ (fullcalendar.bundle.js:35)
at fullcalendar.bundle.js:78
at fullcalendar.bundle.js:81
Uncaught ReferenceError: PerfectScrollbar is not defined
at init (scripts.bundle.js:1448)
at Object.scrollInit (scripts.bundle.js:1462)
at HTMLDivElement.<anonymous> (scripts.bundle.js:1600)
at Function.each (jquery.js?1157:367)
at jQuery.fn.init.each (jquery.js?1157:202)
at initScroll (scripts.bundle.js:1598)
at Object.initComponents (scripts.bundle.js:1659)
at Object.init (scripts.bundle.js:1655)
at HTMLDocument.<anonymous> (scripts.bundle.js:1820)
at mightThrow (jquery.js?1157:3557)
App.vue:
import Vue from 'vue'
import VueFeather from 'vue-feather'
import App from './App.vue'
import router from './router'
import BootstrapVue from 'bootstrap-vue'
Vue.config.productionTip = true
Vue.use(VueFeather)
Vue.use(BootstrapVue)
var WebFont = require('webfontloader');
WebFont.load({
google: {
"families": [
"Poppins:300,400,500,600,700"]
},
active: function () {
sessionStorage.fonts = true;
}
});
const jquery = require('jquery')
window.$ = window.jQuery = jquery
var vendors = document.createElement('script');
vendors.setAttribute('src', './assets/vendors/base/vendors.bundle.js');
vendors.setAttribute('type', 'text/javascript');
document.head.appendChild(vendors);
var scripts = document.createElement('script');
scripts.setAttribute('src', './assets/demo/demo4/base/scripts.bundle.js');
vendors.setAttribute('type', 'text/javascript');
document.head.appendChild(scripts);
var calendar = document.createElement('script');
calendar.setAttribute('src', './assets/vendors/custom/fullcalendar/fullcalendar.bundle.js');
vendors.setAttribute('type', 'text/javascript');
document.head.appendChild(calendar);
var dashboard = document.createElement('script');
dashboard.setAttribute('src', './assets/app/custom/general/dashboard.js');
vendors.setAttribute('type', 'text/javascript');
document.head.appendChild(dashboard);
var bundle = document.createElement('script');
bundle.setAttribute('src', './assets/app/bundle/app.bundle.js');
vendors.setAttribute('type', 'text/javascript');
document.head.appendChild(bundle);
new Vue({
router,
render: h => h(App)
}).$mount('#app')
导入“/assets/vendors/custom/fullcalendar/fullcalendar.bundle.css”
导入“/assets/vendors/base/vendors.bundle.css”
导入“/assets/demo/demo4/base/style.bundle.css”
从“./components/Temp/Header.vue”导入标题
从“./components/Temp/Subheader.vue”导入子标题
从“./components/Temp/Footer.vue”导入页脚
从“./components/Temp/OffcanvasPanel.vue”导入OffcanvasPanel
从“./components/Temp/Quickpanel.vue”导入Quickpanel
从“./components/Temp/Scrolltop.vue”导入Scrolltop
导出默认值{
名称:“应用程序”,
组成部分:{
标题,
分目,
页脚,
选举事务委员会,
快速面板,
卷轴
}
}
我希望所有脚本都能正常工作,看起来像这个演示:
但实际上只有jQuery和Bootstrap起作用。在我看来,它是可以修复的,但我不知道如何修复。在Vue.js论坛上有人问我,他们说我需要在Vue初始化之前尝试插入脚本,我尝试将脚本插入head部分,错误消失了,但在功能上没有区别。但我“神奇地”修复了这个错误:我在关闭body标记后插入了scripts标记,它就工作了。所以,如果有人有类似的错误,请尝试在关闭body标记后插入脚本。Vue.js论坛上有人问我,他们说我需要在Vue初始化之前尝试插入脚本,我尝试将脚本插入头部部分,错误消失了,但在功能上没有差异。但我“神奇地”修复了这个错误:我在关闭body标记后插入了scripts标记,它就工作了。所以,如果有人有类似的错误,请尝试在关闭body标记后插入脚本