ankurk91 / vue-trumbowyg

Vue.js component for Trumbowyg WYSIWYG editor :memo:
https://ankurk91.github.io/vue-trumbowyg/
MIT License
236 stars 35 forks source link

Getting jQuery not defined error on NUXTJS #9

Closed cvsraghava closed 6 years ago

cvsraghava commented 6 years ago

Installation in NUXTJS "npm install vue-trumbowyg --save"

Included a Plugin into NUXT config

import Vue from 'vue'
import VueTrumbowyg from 'trumbowyg'
import 'trumbowyg/dist/ui/trumbowyg.css'
Vue.use(VueTrumbowyg)

HTML code

<template>
  <div>
    <trumbowyg v-model="content" :config="config" class="form-control"></trumbowyg>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        content: '',
        config: {
        }
      }
    }
  }
</script>

Included jQuery on NUXT config**

    script: [
      { src: 'https://unpkg.com/jquery@3.2.1/dist/jquery.min.js' }
    ],

Finally, I am getting error jQuery not defined.

Can anyone please support on this.

ankurk91 commented 6 years ago

I never used this vue component in nuxt.js. I have no idea on how to include jQuery plugins in nuxt.js You can google about it. Here are some related issues https://github.com/nuxt/nuxt.js/issues/356 https://github.com/nuxt/nuxt.js/issues/178

I think you are missing this piece of code.

// webpack config
plugins: [
    new webpack.ProvidePlugin({  
      jQuery: 'jquery',
      $: 'jquery',
      'window.jQuery': 'jquery',
    }),
  ],
ankurk91 commented 6 years ago

ping @cvsraghava

bennettfrazier commented 4 years ago

I never used this vue component in nuxt.js. I have no idea on how to include jQuery plugins in nuxt.js You can google about it. Here are some related issues nuxt/nuxt.js#356 nuxt/nuxt.js#178

I think you are missing this piece of code.

// webpack config
plugins: [
    new webpack.ProvidePlugin({  
      jQuery: 'jquery',
      $: 'jquery',
      'window.jQuery': 'jquery',
    }),
  ],

I know this is old but for anyone referencing - make sure you put this plugin under build: {}

build: {
    plugins: [
      new webpack.ProvidePlugin({
        jQuery: 'jquery',
        $: 'jquery',
        'window.jQuery': 'jquery'
      })
    ]
}
ShisunXia commented 4 years ago

Hi @bennettfrazier , I am also trying to integrate this component in Nuxt js. However, it still shows 'jQuery is not defined' after adding the jquery to the plugins list as you described. Below is my build:

build: {
    transpile: [/^vue-trumbowyg($|\/)/],
    vendor: ['jquery'],
    plugins: [
        new webpack.ProvidePlugin({
            jQuery: 'jquery',
            $: 'jquery',
            'window.jQuery': 'jquery'
        })
    ]
}

I also created a trumbowyg.js file under the plugins folder:

import Vue from 'vue'
import VueTrumbowyg from 'vue-trumbowyg'
import 'trumbowyg/dist/ui/trumbowyg.css'

Vue.use(VueTrumbowyg)

Eventually, I added this line to the plugins list in the nuxt.config.js

plugins: [
        ...
        '~/plugins/trumbowyg.js'
    ],

Thanks in advance.

misaki1301 commented 4 years ago

having same issues after reading webpack guide setup

module: {
      rules: [
        {
          test: /\.(woff|woff2|eot|ttf|svg)(\?.*$|$)/,
          loader: 'file-loader?name=[name].[ext]?[hash]',
        }
      ],
    plugins: [
      new webpack.ProvidePlugin({
        Vue: ['vue/dist/vue.esm.js', 'default'],
        jQuery: 'jquery',
        $: 'jquery',
        'window.jQuery': 'jquery',
      }),
    ],
ShisunXia commented 4 years ago

having same issues after reading webpack guide setup

module: {
      rules: [
        {
          test: /\.(woff|woff2|eot|ttf|svg)(\?.*$|$)/,
          loader: 'file-loader?name=[name].[ext]?[hash]',
        }
      ],
    plugins: [
      new webpack.ProvidePlugin({
        Vue: ['vue/dist/vue.esm.js', 'default'],
        jQuery: 'jquery',
        $: 'jquery',
        'window.jQuery': 'jquery',
      }),
    ],

Hi, I solved my issue by adding mode: 'client' to the plugins importing line. Try to import the plugin in this way: { src: '~/plugins/trumbowyg.js', mode: 'client'}. This is the reference in the documentation.

vmangelovv commented 3 years ago

i have same issue with nuxtjs. - > this.el.trumbowyg is not a function HELP

my plugin/trumbowyg.js

import Vue from 'vue';
import VueTrumbowyg from 'vue-trumbowyg';
import 'trumbowyg/dist/ui/trumbowyg.css';
Vue.use(VueTrumbowyg);

in nuxt.config.js { src: '~/plugins/trumbowyg', mode: 'client' },

and in my .vue file

<template>
  <div>
    <client-only>
      <trumbowyg v-model="content" :config="config" class="form-control"></trumbowyg>
    </client-only>
  </div>
</template>

<script>
export default {
  layout: 'admin',
  data() {
    return {
      content: '',
      config: {},
    };
  },
  methods: {},
};
</script>