无法在9中使用JavaScript库
angular.json无法在9中使用JavaScript库,javascript,angular,Javascript,Angular,angular.json "scripts": [ "node_modules/jquery/dist/jquery.js", "node_modules/popper.js/dist/umd/popper.js", "node_modules/bootstrap-material-design/dist/js/bootstrap-material-design.min.js", "n
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap-material-design/dist/js/bootstrap-material-design.min.js",
"node_modules/arrive/src/arrive.js",
"node_modules/moment/moment.js",
"node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js",
"node_modules/bootstrap-notify/bootstrap-notify.js",
"node_modules/chartist/dist/chartist.js",
"node_modules/vanilla-tilt/src/vanilla-tilt.js" // This ONE!!!
]
香草倾斜JS
尽管通过使用npm install在我的package.json文件中声明了该库,但我无法安装该库并在我的组件中使用它。我也尝试过在index.html中粘贴CDN链接,但都失败了。您不能在index.html中使用来自节点的js。 index.html“存在”在浏览器中,浏览器无法访问节点模块 您可以尝试从index.html中的cdn导入 尝试一下:
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/4.0.2/bootstrap-material-design.umd.min.js"></script>
您可以对vanilla-tilt.js执行同样的操作。将其复制到assets/js文件夹,并尝试使用以下方法:
<script src="assets/js/vanilla-tilt.js"></script>
// or for a quick test:
<script src="https://raw.githubusercontent.com/micku7zu/vanilla-tilt.js/master/dist/vanilla-tilt.min.js"></script>
//或快速测试:
但是:
缺点:这些js文件不会通过构建过程进行压缩(或缩小)。打开节点模块,检查它们是否正确安装。安装后,您可以在应用程序中导入库,例如在组件中导入jquery,您可以这样做
import * as $ from 'jquery';
并使用$
和jquery方法
类似地,您也可以使用其他库,如
import * as moment from 'moment'
然后使用
moment(someValue).format('L')
如果使用dist文件而不是源文件,会发生什么?(vanilla-tilt/dist/vanilla-tilt.min.js
)是您的错误,它没有捆绑,或者您不能在代码中使用它?console中没有错误,但在代码中也不起作用@argeePut package.json中的库名称以及您想要安装的版本,然后执行npm install将尝试DIST@seblor使用just.js文件复制脚本标记不会显示错误,也不会工作。githubusercontent显示“来自的资源”https://raw.githubusercontent.com/micku7zu/vanilla-tilt.js/master/dist/vanilla-tilt.min.js“由于MIME类型(“文本/普通”)不匹配(X-Content-type-Options:nosniff)而被阻止。”
在控制台中