我使用Vuejs,并将所有Vue.js代码放在index.html中的脚本标记中。它工作得很好。但是,我想使用this组件来添加标签功能。
但是我收到了这个错误

:
我的代码是这样的:
<script>
import VTagInput from 'v-tag-input'
Vue.use(VTagInput)
var app = new Vue({
el: '#app',
delimiters: ["[[", "]]"],
components: {VTagInput},
tags: []
data: {
errors: [],I npm按照github代码库中指定的方式安装了该包。
这是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>发布于 2018-02-13 23:03:18
你不能使用‘导入’在浏览器中导入其他文件你需要使用webpack,但是你可以在加载vue.js文件https://unpkg.com/v-tag-input@0.0.3/dist/v-tag-input.js之后使用这个cdn在你的html中加载插件,这是一个工作示例
new Vue({
el:"#app",
data: {
tags: ['foo', 'bar']
}
})<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>
发布于 2018-02-13 22:59:12
你应该把脚本加载到你头脑中VTagInput所在的位置,就在Vue之后。这样就不需要导入任何东西了,VTagInput将可以全局访问
https://stackoverflow.com/questions/48769543
复制相似问题