Vue syntax is essentially standard JS, but with some extra functionalities. This allows you to easily import NPM packages into your Vue components using a simple import statement within the <script>
tag.
For instance:
import axios from 'axios';
export default {
...
methods: {
doSomething() {
axios.get(...)
}
}
}
Some packages may provide specific methods and properties for you to import. In such cases, you can use "destructuring" to only import what you need from the package instead of the entire package:
import { method_1, method_3, property_a } from 'myPackage';
export default {
data() {
return {
myComponentProperty: property_a
}
},
...
methods: {
doSomething() {
const a = 'something';
const b = method_1(a);
return b;
}
}
}
In general, locate your desired package on https://www.npmjs.com/ and follow the provided instructions for importing and utilizing it in your project. The website typically offers examples on how to import and implement the package effectively.