0

I'm testing an API that helps me with the project I'm working on, and it's possible to install your NPM, its name is "parallax-js", so I looked for how to import, however I didn't have any results in my research, and I can't understand how I import an external script into VUE.

Here's the way I'm trying to put my project together in VUE.

APP VUE

<template>
  <div id="app">

    <img alt="Vue logo" src="./assets/logo.png" data-depth="0.2">
    <HelloWorld msg="Welcome to Your Vue.js App" data-depth="0.2"/>
  
    {{alpha()}}

  </div>

  
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
import '../node_modules/parallax-js/src/parallax.js'

export default {
  name: 'App',
  components: {
    HelloWorld
  },
  methods : {

    alpha(){

      let scene = document.getElementById('app');
      let parallaxInstance = new Parallax(scene);

    }

  }
}

</script>

The point is ... I want to know how to learn the best way to import an external script ... and how I use the variables and objects inside that script.

2
  • 1
    you should do this import Parallax from 'parallax-js' Commented Jul 14, 2020 at 19:50
  • I already tried it, it didn't go wrong ... but still I can't use the API ... I can't use its functions as new Parallax(scene) Commented Jul 14, 2020 at 19:54

2 Answers 2

1

{{alpha()}} it is not how you call a method. Usually this is done in mounted hook:

mounted() {
  this.alpha()
}

Also, it seems that you may want to learn the basics of VueJS, and this is not the right place. You can start with the VueJS documentation provided on their website (https://v2.vuejs.org/v2/guide/)

Sign up to request clarification or add additional context in comments.

1 Comment

Ok... this was of great help, but I'm still not able to use the new Parallax(scene) function from within the script/API
1

Like I said in the comment section you were supposed to import it and finally call your method when vue is mounted.

<template>
  <div id="app">
  <img alt="Vue logo" src="./assets/logo.png" data-depth="0.2" />
  <HelloWorld msg="Welcome to Your Vue.js App" data-depth="0.2" />
  </div>
</template>

<script>
import HelloWorld from "./components/HelloWorld.vue";
import Parallax from "parallax-js";

export default {
name: "App",
components: {
HelloWorld,
},
methods: {
alpha() {
  let scene = document.getElementById("app");
  let parallaxInstance = new Parallax(scene);
 },
},
 mounted() {
 this.alpha();
 },
};
</script>

4 Comments

That's what Igor Moraru just answered, and in return I will say the same thing ... it makes more sense the way it is calling alpha()... but the new Parallax(scene) function is not being recognized as a occupation
I don't really get your last statement if you could come again? Is the parallax still not working?
So... I solved this by changing the API... in fact, this post from StackOverflow needed to be "closed" or something else... I don't know if I asked the right question... however it is ... what you answered is right... but I think the API is having trouble calling some functions.
Yes ... but Igor Moraru already answered first he deserves the credit for the answer... I was just waiting for someone who could answer how I could get the script function and use it in my component.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.