1

I use Vue.js CDN and I put all the Vuejs code inside a script tag in index.html. It works fine. However, I'd like to use this component to add tags functionality.

But I receive this error this :

This is how my code looks like:

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

I npm installed the package as specified in the github repo.

This is the head tag:

<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>
7
  • are you using webpack? Commented Feb 13, 2018 at 14:53
  • @Mohd_PH I only use CDN for Vue, JQuery and Axios Commented Feb 13, 2018 at 14:54
  • You cant use import in browsers yet, nor require Commented Feb 13, 2018 at 14:57
  • when using CDN, a global variable should be created, so what matter is the order of the scripts tags, it should be vue, vue-tag, and there is no need to use import Commented Feb 13, 2018 at 14:57
  • @AngelSalazar vue-tag don't have CDN so I npam installed it. Commented Feb 13, 2018 at 14:59

2 Answers 2

7

You cant import another files in browser using 'import' you need to use webpack, however you can use this cdn to load the plugin in your html after loading vue.js file, https://unpkg.com/[email protected]/dist/v-tag-input.js , here is a working example

new Vue({
	el:"#app",
  data: {
    tags: ['foo', 'bar']
  }
})
<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/v-tag-input.js"></script>

<div id="app">
  <v-tag-input v-model="tags"></v-tag-input> {{tags}}
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

You should load the script where VTagInput is located in your head, right after Vue. Then no need to import anything, VTagInput will be accessible globally

4 Comments

I added my head tag to the question. I npm installed VTagInput, it's not in the head as they don't have CDN, it's the only thing that I need to 'import'
I ran npm i --save v-tag-input
Just put the relative location or their CDN: unpkg.com/[email protected]/dist/v-tag-input.js
--save add only an entry to the package.json. you will find the library and the dist folder in your node_modules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.