在main.js中引入后,组件内使用$报$未定义,只有在组件中重新引入才可以。
除了在index.html中直接引用外,在main.js中该怎么全局引用?
在main.js中引入后,组件内使用$报$未定义,只有在组件中重新引入才可以。
除了在index.html中直接引用外,在main.js中该怎么全局引用?
可以像1楼一样挂载到window上面成为一个全局变量。
但是在vue中一般也可以这么做:
import jquery from 'jquery'
Vue.prototype.$ = jquery
使用的时候,直接$.ajax
这样
npm i -D @types/jquery
index.html
<script src="//cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
webpack
externals: {
jquery: 'jQuery'
}
main.js