我正在使用 jquery 在我的 nuxt js 应用程序中显示一个弹出窗口并在本地主机和开发环境中工作 nuxt.config.js
script: [
{
src: "~plugins/jquery-3.4.1.min.js",
type: "text/javascript"
},
],
plugins: [
"'~plugins/jquery-3.4.1.min.js"
],
答案 0 :(得分:0)
不确定为什么要在 Vue/Nuxt 项目中包含 jQuery(这在某种程度上会适得其反),但我想您可以将它包含在 CDN 中,并且它可以在任何环境中完美运行。
script: [
{
src: "https://code.jquery.com/jquery-3.3.1.slim.min.js",
type: "text/javascript"
}
]
或者这样,更干净一些
yarn add jquery
const webpack = require("webpack");
module.exports = {
build: {
vendor: ["jquery"],
plugins: [
new webpack.ProvidePlugin({
$: "jquery"
})
],
}
};
从此处获取的设置示例:https://kaloraat.com/articles/how-to-use-jquery-in-nuxtjs