我被要求将新的html页面添加到vuejs项目中。此页面已经完全开发,基于jquery和一些twitter-bootstrap功能。将自举功能包含到自定义vuejs组件中
我创建了一个新组件。
newPage.vue
<template>
<div id="my-new-page">
...
</div>
</template>
<style src="path/to/_bootstrap.scss" lang="scss" scoped></style>
<style src="path/to/font-awesome.scss" lang="scss" scoped></style>
<style src="path/to/animate.css" scoped></style>
<style src="path/to/custom/css.css" scoped></style>
<script src="path/to/custom/js.js"></script>
js.js
import jQuery from 'jquery';
// Same error even with window.$ = window.jQuery = jQuery;
import collapse from 'path/to/bootstrap/feature/collapse.js";
export default {
created() {
runjQuery(jQuery);
},
};
function runjQuery($) {
// here is how I thought integrate the jquery script of the new html page
$(function() {
....
$('#navbar').collapse('hide');
});
}
但是,这显然是行不通的,因为collapse.js
无法访问jQuery
,我得到这个错误
Uncaught ReferenceError: jQuery is not defined
我该如何解决这个问题?
鉴于我不想(如果可能)将bootstrap和jquery全局添加到我的项目中,因为这肯定会在我的其他组件中出现断点续传吗?
你看过vue-strap吗? https://wffranco.github.io/vue-strap/ – enriqg9
@ enriqg9有没有我需要的所有功能,例如崩溃 – smarber
我怀疑你需要括号形式的'import'。请参阅https://stackoverflow.com/a/43546877/392102 –