0

I want USD to be taken from api which function I've in methodsbut how can I write it ?

  data(){
      return {
        posts: 1,
        USD:changeCurrency()
      }
  },
  methods: {
    changeCurrency: function () {
      axios.get('http://data.fixer.io/api/latest?access_key=509c9d50c1e92a712be9c8f1f964cf67')
      .then(response => {
        this.posts = response.data.rates.GEL.toFixed(3)
      })
    }
1
  • How do you use your rate? Show template. Commented Jan 8, 2020 at 22:34

1 Answer 1

2

That is not how data is supposed to be used.

You can call changeCurrency in mounted or in the component itself @click="changeCurrency"

{
    data() {
        return {
            posts: 1,
            // USD:changeCurrency()
        };
    },
    mounted() {
        // you could call here instead
        this.changeCurrency();
    },
    methods: {
        changeCurrency: function () {
            axios.get('http://data.fixer.io/api/latest?access_key=509c9d50c1e92a712be9c8f1f964cf67')
                .then(response => {
                    this.posts = response.data.rates.GEL.toFixed(3);
                });
        }
    }
}
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.