vue.js - 我可以在 bootstrap-vue 项目中安全地包含 bootstrap.js 吗?
问题描述
我正在开发一个类似于计算器的小型 VueJS 应用程序,它将安装到 Bootstrap 4 主题 CMS 上现有“静态”页面中的 DOM 元素。导航栏和其他网站功能都依赖于 vanilla Bootstrap 4 CSS/JS。页面的非 Vue 和 Vue 部分之间不会有任何 DOM 交互。非 Vue 部分是简单的内容和导航。
目前,不使用 Bootstrap-Vue,一切正常。
我想在页面的 VueJS 托管部分中使用 Bootstrap-Vue 组件。根据这些组件的文档:
如果您已经在使用 Bootstrap 4,您可能需要对项目进行一些调整:[1] 从页面脚本或构建管道中删除 bootstrap.js 文件,[2]...
由于页面的非 Vue 部分使用 bootstrap.js,我可以简单地在运行时同时包含 bootstrap.js 和 bootstrap-vue.js 库吗?有什么我应该注意的问题吗?
解决方案
在下面的示例中,我使用了两部分,第一部分指定给 Vue,另一部分仅用于引导程序。
我提供了以下简化示例来向您展示如何做到这一点
new Vue({
el: '#app',
data() {
return {
item:'',
currentPassword:'',
req:false
}
},
methods: {
changePassword: function() {
this.req=true;
}
}
});
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css" />
<!-- Add this after vue.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<body>
<div id="outOfVue">
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
</div>
<div id="app" class="container">
<div>
<b-form validated="" id="passwordChangeForm" @submit.prevent="changePassword" class="container-fluid">
<b-form-group id="currentPassword" label="Old password">
<b-form-input id="password" v-model="currentPassword" placeholder="Enter your old Password" type="password" :required="req" />
</b-form-group>
<b-button type="submit" variant="primary">Submit</b-button>
</b-form>
</div>
</div>
</body>
推荐阅读
- c++ - C++ 生成随机向量
- sql - SSIS根据另一个表中的行动态选择列名
- vb.net - 在哪里设置代码以限制用户访问而不使用 web.config
- perl - 除非和 grep 不能正常工作
- ubuntu - Jenkins 抛出错误:jenkins.model.InvalidBuildsDir: ${ITEM_ROOTDIR}/builds 不存在并且可能无法创建
- java - 在 JavaFX 中使用 vert.x http 服务器
- angular - Redux 状态缺少来自 redux 离线的“离线”部分
- jenkins - 主动/动态选择参数 - 填写特定的作业名称
- android-studio - Android Studio USB调试
- ibm-cloud - Watson Assistant 对话框 - 无法进入子节点