【问题标题】:jquery not working in deployment but working in local nuxtjs?jquery 不在部署中工作,但在本地 nuxtjs 中工作?
【发布时间】:2021-06-28 08:24:43
【问题描述】:

我正在使用 jquery 在我的 nuxt js 应用程序中显示一个弹出窗口,并在 localhost 和开发环境中工作 nuxt.config.js

script: [
  {
    src: "~plugins/jquery-3.4.1.min.js",
    type: "text/javascript"
  },
],
plugins: [  
  "'~plugins/jquery-3.4.1.min.js"
],

【问题讨论】:

  • 如果您希望我们为您提供帮助,请提供有关生产中发生的情况的更多详细信息。 How to Ask 另外,为什么脚本和插件做同样的工作?

标签: jquery vue.js nuxt.js


【解决方案1】:

不确定为什么要将 jQuery 包含在 Vue/Nuxt 项目中(它在某种程度上会适得其反),但我想您可以将它包含在 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

你也可以试试这个:https://stackoverflow.com/a/57508835/8816585

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 2021-05-22
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多