簡體   English   中英

在 nuxt.js 中使用 jquery.easing 時“$.extend 不是函數”

[英]"$.extend is not a function" while using jquery.easing in nuxt.js

我在 Vue.js 中制作了一個應用程序,我正在嘗試在 Nuxt.js 中進行調整。 對於 scrollspy,我在 Vue.js 中使用了jquery.easing ,所以我想在 Nuxt.js 中做同樣的事情。

有點像你在 Vue.js main.js文件中導入 jQuery,我在 Nuxt 中創建了一個插件來添加 jQuery 和require("jquery.easing")

插件/jqueryeasing.js

import Vue from "vue";
import jquery from "jquery";

require("jquery.easing");

Vue.prototype.jquery = jquery;

我還將它鏈接到我的nuxt.config.js文件:

const webpack = require("webpack");

module.exports = {
  /*
   ** Headers of the page
   */
  head: {
    title: "resume",
    meta: [
      { charset: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1" },
      { hid: "description", name: "description", content: "undermaintenance" }
    ],

    link: [
      { rel: "icon", type: "image/x-icon", href: "/favicon.ico" },

  css: [
    // this line include bootstrap.css in each html file on generate
    "~/node_modules/bootstrap/dist/css/bootstrap.css",
    // main css file in document
    "assets/css/main.css"
  ],

  /*
   ** Plugin section
   */
  plugins: [
    "~plugins/bootstrap.js"
    "~plugins/jqueryeasing.js",
  ],

  /*
   ** Build configuration
   */
  build: {
    /**
     * add external plugins
     */
    vendor: ["jquery", "bootstrap"],
    plugins: [
      new webpack.ProvidePlugin({
        $: "jquery"
      })
    ],
    /*
     ** Run ESLint on save
     */
    extend(config, { isDev, isClient }) {
      if (isDev && isClient) {
        config.module.rules.push({
          enforce: "pre",
          test: /\.(js|vue)$/,
          loader: "eslint-loader",
          exclude: /(node_modules)/
        });
      }
    }
  }
};

jQuery 與我的 Bootstrap 一起工作就像一個魅力。

我不知道為什么,但我有這個

typeError: $.extend 不是函數。

它來自我的node_modules/jquery.easing/jquery.easing.js文件。

$.extend($.easing, {
  def: "easeOutQuad",
  swing: function(x) {
    return $.easing[$.easing.def](x);
  },
  easeInQuad: function(x) {

版本信息:

"jquery": "^3.3.1",
"jquery.easing": "^1.4.1"

我試過:

  • 使用 jQuery 的擴展版本
  • 添加 jQuery UI: "jquery-ui": "^1.12.1" ,
  • 僅在nuxt.config.js文件中使用 CDN 和腳本
  • 使用舊版本的 jQuery 和jQuery.easing

我做錯了什么,它如何在 Vue.js 中工作?

如果您使用的是 Jquery-easing,簡單的方法是像這樣添加它:

 1- Inside your nuxt.config.js
  script: [
  {
    src:
  'https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js'
  }     
]

J-query 和 Nuxt.js 不是最好的朋友。

我使用了一個名為 vuetifyjs 的插件。 您將找到一個滾動goTo功能,您可以在其中修復包括平滑滾動(使用內置緩動功能)、持續時間和偏移在內的選項。

這是文檔的鏈接: https : //next.vuetifyjs.com/en/framework/scroll

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM