简体   繁体   English

使用Vue.js / Bootstrap-vue.js CDN和组件

[英]Using Vue.js / Bootstrap-vue.js CDN and components

forgive my ignorance here, I am super new to Vue. 原谅我的无知,我是Vue的新手。 I am looking for a way to utilize bootstrap-Vue from CDN ( https://bootstrap-vue.js.org/docs/ click browser on right nav). 我正在寻找一种利用CDN的bootstrap-Vue的方法( https://bootstrap-vue.js.org/docs/单击右侧导航栏上的浏览器)。 I am not seeing how to call the components. 我没有看到如何调用组件。 Using the webpack / CLI version, no problems, but CDN, I am lost at how to use this. 使用webpack / CLI版本,没问题,但是CDN,我不知道该如何使用它。

I put up a simple codepen.io to test this. 我建立了一个简单的codepen.io来测试这一点。 I've added the CSS and js files per the docs. 我已经根据文档添加了CSS和js文件。

https://codepen.io/jasonflaherty/pen/rrzbxj https://codepen.io/jasonflaherty/pen/rrzbxj

//do I need this?
Vue.use(BootstrapVue);

//try individual components.
import { Card } from 'bootstrap-vue/es/components';
Vue.use(Card);

What am I missing to utilize bootstrap-vue.js CDN? 使用bootstrap-vue.js CDN我缺少什么? Do I need to import differently? 我需要以其他方式导入吗?

If you use the CDN, you do not need to use the BootstrapVue plugin; 如果使用CDN,则无需use BootstrapVue插件; it will do that for you. 它将为您做到这一点。 Just including the script adds all the BootstrapVue components globally. 仅包含脚本会全局添加所有BootstrapVue组件。

You cannot use ES6 import statements in the browser. 您不能在浏览器中使用ES6 import语句。

You do need to create a Vue. 确实需要创建一个Vue。

Here is your pen updated . 这是您的笔更新了

You should to use a basic structure of Vue. 您应该使用Vue的基本结构。 So, your JS should be: 因此,您的JS应该是:

const vue = new Vue({
  el: "#app"
})

And is necessary that your HTML code stay into a: 而且,您的HTML代码必须位于:

<div id="app">
   <!-- ...your code -->
</div>

Just include the required CDN below and without invoking Vue.use(XXX) (There is a Basic example from the official website.) 只需在下面包含所需的CDN,而不调用Vue.use(XXX) (官方网站上有一个基本示例 )。

        <!-- Required Stylesheets -->
        <link
          type="text/css"
          rel="stylesheet"
          href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css"
        />
        <link
          type="text/css"
          rel="stylesheet"
          href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"
        />

        <!-- Required scripts -->
        <script src="https://unpkg.com/vue"></script>
        <script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>


When you run the Basic example , you will get the bootstrap decoration. 当您运行Basic示例时 ,您将获得bootstrap装饰。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM