我可以安全地将 bootstrap.js 包含在 bootstrap-vue 项目中吗?
Can I safely include bootstrap.js in bootstrap-vue project?
我正在开发一个类似于计算器的小型 VueJS 应用程序,它将安装到 Bootstrap 4 主题 CMS 上现有 "static" 页面中的 DOM 元素。导航栏和其他站点功能都依赖于 vanilla Bootstrap 4 CSS/JS。页面的非 Vue 和 Vue 部分之间不会有任何 DOM 交互。非 Vue 部分是简单的内容和导航。
目前,不使用 Bootstrap-Vue,一切正常。
我想在页面的 VueJS 管理部分中使用 Bootstrap-Vue 组件。根据这些组件的文档:
If you've already been using Bootstrap 4, there are a couple adjustments you may need to make to your project: [1] Remove the bootstrap.js file from your page scripts or build pipeline, [2]...
由于页面的非 Vue 部分使用 bootstrap.js,我能否在运行时简单地同时包含 bootstrap.js 和 bootstrap-vue.js 库?我应该注意什么问题?
在下面的示例中,我使用了两个部分,一个指定给 Vue,另一个指定给 bootstrap。
我提供了以下简化示例来向您展示如何做到这一点
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>
我正在开发一个类似于计算器的小型 VueJS 应用程序,它将安装到 Bootstrap 4 主题 CMS 上现有 "static" 页面中的 DOM 元素。导航栏和其他站点功能都依赖于 vanilla Bootstrap 4 CSS/JS。页面的非 Vue 和 Vue 部分之间不会有任何 DOM 交互。非 Vue 部分是简单的内容和导航。
目前,不使用 Bootstrap-Vue,一切正常。
我想在页面的 VueJS 管理部分中使用 Bootstrap-Vue 组件。根据这些组件的文档:
If you've already been using Bootstrap 4, there are a couple adjustments you may need to make to your project: [1] Remove the bootstrap.js file from your page scripts or build pipeline, [2]...
由于页面的非 Vue 部分使用 bootstrap.js,我能否在运行时简单地同时包含 bootstrap.js 和 bootstrap-vue.js 库?我应该注意什么问题?
在下面的示例中,我使用了两个部分,一个指定给 Vue,另一个指定给 bootstrap。
我提供了以下简化示例来向您展示如何做到这一点
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>