Reputation: 547
I'm very new to nuxt and javascript and I'm trying to figure out how to use my app's dependencies client-side. I have them listed in my nuxt.config.js and installed with npm. I also have a file in the /plugins
directory that imports them (not sure if this is good or not). Here is where I run into trouble: I have two scripts located in my /static
directory that need to take advantage of my npm packages. Putting an import statement in those scripts causes an error. Importing the packages in the script section of the page vue file also doesn't work. How can I use npm packages in scripts that are included in pages client-side?
Upvotes: 4
Views: 9269
Reputation: 41
Can you provide a more information, about which kind of error is happening and which kind of packages did you try to install?
In this example I am going to show you how I included in my nuxt project npm package vuelidate
after installing vuelidate:
plugins: [
{ src: "~/plugins/vuelidate", mode: "client" },
],
import Vue from 'vue'
import Vuelidate from 'vuelidate'
Vue.use(Vuelidate);
<script>
import { required, minLength } from "vuelidate/lib/validators";
export default {
name: "OrderByLinkForm",
components: {},
...
};
</script>
Upvotes: 1