0

I am exporting a function from an external js file and trying to manipulate a Vue data bu that way but currently, I am not able to that. Here is what I tried so far :

Imported js file like this :

import * as device from "../Device"; 

Invoked the method like this :

device.playURL(this.currentTVChannelUrl,this.loading,this.isPlayerShown);

Here is the method named playURL inside device.js file :

export function playURL(url,loading,isPlayerShown){
    player.play({
      uri: url,
    });
      loading = false;
      isPlayerShown = true;
}

It doesn't change the manipulative data of my Vue component. Is there a way to change them?

1
  • 1
    you can add playURL in your Vue root instance events and dispatch it from your child component Commented Apr 30, 2020 at 23:40

1 Answer 1

1

You can bind the this context of playURL to the current component and make this to work.

let bindedplayURL = device.playURL.bind(this);
bindedplayURL(this.currentTVChannelUrl)
playURL(url) {
  player.play({
    uri: url,
  });
  this.loading = false /* changes data in vue component directly no need to pass these varibles separately */
  this.isPlayerShown = true;
}

However, if you've created the playURL function for the reason to use it at various places inside Vue files. I'd even suggest you to look at Mixins in vue which solve this purpose only and they would intelligently mix the data and methods themselves.

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

Comments

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.