我正在开发一个类似于计算器的小型VueJS应用,该应用将安装在Bootstrap 4主题CMS上现有“静态”页面中的DOM元素上。导航栏和其他站点功能都依赖于香草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库吗?我应该注意的任何问题?
答案 0 :(得分:1)
在以下示例中,我使用了两部分,第一部分指定给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>