jquery - VueJS - 未定义 Jquery
问题描述
我正在尝试创建一个使用预制 css 样式的 Vue 组件,但问题是我不断收到以下错误,因为模板使用引导程序并且引导程序使用一些 jquery:
custom.js?2435:952 Uncaught ReferenceError: jQuery is not defined
代码:
组件.vue
<template>
<html>
<body>
...
</body>
</html>
</template>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="./Crypo/assets/js/jquery-3.4.1.min.js"></script>
<script src="./Crypo/assets/js/popper.min.js"></script>
<script src="./Crypo/assets/js/amcharts-core.min.js"></script>
<script src="./Crypo/assets/js/amcharts.min.js"></script>
<script src="./Crypo/assets/js/jquery.mCustomScrollbar.js"></script>
<script src="./Crypo/assets/js/custom.js"></script>
<style scoped src="./Crypo/assets/css/style.css"></style>
该Crypo
文件夹与component.vue
. 我不明白为什么没有定义 jQuery,即使我正在导入它。我试图添加到我的代码
import jQuery from 'jquery'
但我仍然收到错误消息。有什么解决办法吗?
解决方案
您在这里有一些选择:
或者你把这些链接放到 index.html
- public
- index.html
就像这里一样:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="./Crypo/assets/js/jquery-3.4.1.min.js"></script>
<script src="./Crypo/assets/js/popper.min.js"></script>
<script src="./Crypo/assets/js/amcharts-core.min.js"></script>
<script src="./Crypo/assets/js/amcharts.min.js"></script>
<script src="./Crypo/assets/js/jquery.mCustomScrollbar.js"></script>
<script src="./Crypo/assets/js/custom.js"></script>
...
或者,您可以使用bootstrap-vue通过 npm(首选)安装所有内容
npm install vue bootstrap-vue bootstrap
并将其导入您的应用程序入口点,如下所示:
import Vue from 'vue'
// bootstrap lib import
import { BootstrapVue, IconsPlugin } from 'bootstrap-vue'
// css imports
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
// Install BootstrapVue
Vue.use(BootstrapVue)
// Optionally install the BootstrapVue icon components plugin
Vue.use(IconsPlugin)
另一件事是,你不应该在 vue 组件中使用 html 或 body 标签,它们应该只在 index.html 文件中使用。
推荐阅读
- ruby-on-rails - LoadError: 无法加载此类文件 -- config/deploy
- tensorflow - 批量大小数字而不是 None
- sql - SQL Server如何将一个表中的列复制到另一个表中
- c - C 删除链表节点
- python - 如果可以在 python tkinter 中绑定使用.place() 定位的标签?
- c - 在 CODE COMPOSER 的 MSP432 c 程序中做 Simon 说(随机 LED)
- android - java.lang.RuntimeException:无法创建类 com.example.breatheeasy.userinterface.viewmodels.MainViewModel 的实例
- python - Python 魔术命令 %store 在 Google Colab 笔记本上不起作用
- r - 如何旋转具有两列和 R 中每个组的多个观察值的数据框?
- windows - 如何以链接方式在 Windows 中运行程序,就像在 Ubuntu 中的终端中一样?