如何将Vuejs组件“导入”到index.html?

Sei*_*eif 0 html javascript tags vue.js npm-install

我使用Vue.js CDN,并将所有Vuejs代码放入index.html中的脚本标签中。工作正常。但是,我想使用组件来添加标签功能。

但是我收到这个错误 这个

这是我的代码的样子:

     <script>
      import VTagInput from 'v-tag-input'
      Vue.use(VTagInput)
      var app = new Vue({
        el: '#app',
        delimiters: ["[[", "]]"],
        components: {VTagInput},
        tags: []
        data: {
          errors: [],
Run Code Online (Sandbox Code Playgroud)

我npm安装了github repo中指定的软件包。

这是head标签:

<head>
      <meta charset="utf-8">
      <meta name="author" content="Seif Elmughrabi">
      <!-- Compiled and minified CSS -->
      <link rel="stylesheet" href="(( url_for('static', filename='materialize.css') ))" media="screen, projection">
      <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic|Material+Icons">
      <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css"> -->
      <!--Google Icons-->
      <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
      <link rel="stylesheet" href="(( url_for('static', filename='style.css') ))">
      <!--Let browser know website is optimized for mobile-->
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

      <title>Your Insurance Policy Planner</title>
    </head>
Run Code Online (Sandbox Code Playgroud)

Moh*_*_PH 5

您无法使用需要使用Webpack的“导入”功能在浏览器中导入其他文件,但是在加载vue.js文件https://unpkg.com/v-tag-input后,可以使用此CDN在HTML中加载插件@ 0.0.3 / dist / v-tag-input.js,这是一个有效的示例

new Vue({
	el:"#app",
  data: {
    tags: ['foo', 'bar']
  }
})
Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/vue@2.5.13/dist/vue.min.js"></script>
<script src="https://unpkg.com/v-tag-input@0.0.3/dist/v-tag-input.js"></script>

<div id="app">
  <v-tag-input v-model="tags"></v-tag-input> {{tags}}
</div>
Run Code Online (Sandbox Code Playgroud)