Vue3 引入 jquery
通过 js包的方法 引入 jquery
当然也可以用 npm install jquery --save-dev 方法
但 引用 js包 方法 配置相对简单,在npm遇到问题时可采用此种方式
一.下载 jquery压缩包
官网下载:jquery.com/download/
二.在根目录下 public文件夹里的 index.html 中引入jquery
在 public 文件夹中新建 js 文件夹用来存放下载的 js 包
<script src="./js/jquery.min.js"></script>
三.在 package.json 中添加 eslintConfig 配置块 "jquery": true
否则会一直报错!!
注:末尾没有 逗号
"eslintConfig": {
"root": true,
"env": {
"node": true,
"jquery": true //新增这一行
},
四、使用示例
html
<div id="localtime" class="hdtime">测试 jquery</div>
js
mounted() { this.page_init(); }, methods: { page_init(){ console.log($('#localtime').html()); } },
输出