我有一个项目,我想用VuePress记录,我有一个小代码,需要运行jQuery . 我知道你可以添加内联脚本标签并将代码放入其中,但我似乎无法添加jQuery . 这是文件夹结构和我尝试过的内容:

docs
   .vuepress
   -- dist
   -- public
      -- css
      -- js
         -- jquery-3.3.1.min.js
         -- scripts.js
   -- config.js
   components.md

在components.md中,我在最后添加了以下内容:

<script src="/js/jquery-3.3.1.min.js"></script>

这是在脚本标记中添加jquery时的错误:

Module not found: Error: Can't resolve '../../../../../../js/jquery-3.3.1.min.js?vue&type=script&lang=js&' in C:/Users/../docs
 @ ./node_modules/vuepress/lib/app/.temp/routes.js
 @ ./node_modules/vuepress/lib/app/app.js
 @ ./node_modules/vuepress/lib/app/clientEntry.js
 @ multi ./node_modules/vuepress/lib/app/clientEntry.js

module.exports.head 中添加config.js中的css是有效的,但由于某种原因添加javascript并不是't work (jquery gets added, but sometimes it works and most of the time it doesn' t) . 这是我在config.js中尝试过的

head: [
["link",{ rel: "stylesheet", href: "/css/bootstrap-4.1.3/bootstrap reboot.css" } ],
["link",{ rel: "stylesheet", href: "/css/bootstrap-4.1.3/bootstrap-grid.css"}],
["link", { rel: "stylesheet", href: "/css/bootstrap-custom.css" }],
["link", { rel: "stylesheet", href: "/css/style.css" }],
["script", { src: "/js/jquery-3.3.1.min.js" }],
["script", { src: "/js/scripts.js" }]
]

编辑:我测试了一点,显然,即使脚本是导入的,我也无法选择我想要选择的元素 . 例如$(' . my-elements')返回一个空选择器 . 另一方面,document.getElementsByClassName('my-elements')工作并将我想要的元素显示为第一个数组元素,但如果我想在结尾处选择[0]的第一个数组元素,则返回undefined .

我尝试使用上面的2个函数在控制台中选择元素 . 相同的功能在控制台中工作,但在脚本中不起作用,这很奇怪 .