0

newbie in coding here.

I have to call an API in which I have to change some parts of the querystring to retrieve different results

Briefly explained:

<template>
      <div>
        <input type="text" v-model="param" />
      </div>
      <div>
        <input type="text" v-model="param2" />
      </div>
</template>

This would modify the following URL in the script zone:

http://localhost:7000/mock?mockingCode=${param}&mockingCode2=[B]${param2}

2 Answers2

1

That is exactly what computed is for: https://v2.vuejs.org/v2/guide/computed.html

    computed: {
        url() {
            return `http://localhost:7000/mock?mockingCode=${this.param}&mockingCode2=[B]${this.param2}`;
        }
    },
tony19
  • 125,647
  • 18
  • 229
  • 307
Dennis Utzinger
  • 110
  • 1
  • 7
0

you can use watch():

data() {
  return {
    param: '',
    param: '',
    url: 'http://localhost:7000/mock?',
  }
}
watch() {
  param() {
    this.url += '`mockingCode=${this.param}&`';
  }
  param() {
    this.url += '`mockingCode2=[B]${this.param2}&`';
  }
}

Nothehi
  • 695
  • 6
  • 19