Using VueJS to dynamically manipulate URL parameters with v-model

Hello, I am new to coding.

I am working on calling an API where I need to adjust parts of the querystring for different results.

To explain briefly:

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

By doing this, the specified URL in the script section would be modified as follows:

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

Answer №1

Using the computed property is essential for this task: https://v2.vuejs.org/v2/guide/computed.html

    computed: {
        link() {
            return `http://localhost:7000/mock?mockingCode=${this.param}&mockingCode2=[B]${this.param2}`;
        }
    },

Answer №2

To implement dynamic changes, you can utilize the watch() method:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing JavaScript to dynamically set a CSS file from an API in AngularJS

I am currently facing an issue with integrating a CSS file returned by an API into my entire website. Since the URL of the CSS file keeps changing, hard coding the URL is not feasible. While I have successfully implemented this on 'view1', my goa ...

The children of vue-jstree remain closed when loading data through the api

<v-jstree :data="treeData" textFieldName="nameField" @item-click="handleItemClick" /> If I decide to use static data instead, it works perfectly: data() { return { tre ...

Encountering problem with image file encoding while using res.download in Express.js

My node.js server with expressjs is set up for local development, where I store and retrieve various files through basic HTTP calls. Most of the time, everything works smoothly. However, on rare occasions, a small number of files return to the end-user sig ...

Is it advisable to encapsulate my entire Express server within a TypeScript class?

After working extensively with nodeJs, I have decided to explore developing applications in Typescript. Recently, I came across various blogs (like this one) that recommend wrapping modules and the app's entry point in a class when creating a RESTful ...

Tips for passing a function and an object to a functional component in React

I am struggling with TypeScript and React, so please provide clear instructions. Thank you in advance for your help! My current challenge involves passing both a function and an object to a component. Let's take a look at my component called WordIte ...

Turn off bodyparser when uploading files in Node.js

This query is quite similar to another one on Stack Overflow regarding how to disable Express BodyParser for file uploads in Node.js. The solution provided there was for Express3, but when tested with the updated Express 4, it didn't work as expected. ...

Receiving messages in AngularJS with the help of Strophe.js

My XMPP client in AngularJS, inspired by this stackoverflow link. <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d282e382f1d282e382f7331323e3c31">[email protected]</a> can send messages successfully, but <a hr ...

What is the best way to attach a CSS class using an onclick function?

I need to dynamically apply a CSS class to a specific div when clicked using JavaScript. Here is the HTML structure: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv=&qu ...

Struggling to populate a nested array in a dropdown using AngularJS

I am currently working on populating JSON data into a dropdown list, specifically focusing on main category, sub category and sub sub category. Successfully managed to populate the main category and sub category, but facing challenges with populating subsu ...

How can we define a method in Vue.js similar to Handlebars.registerHelper?

Transitioning from "Handlebarjs" to "Vuejs", I am looking to define a method that can be used in multiple sections of my code. Similar to Handlebars.registerHelper(); Any assistance would be greatly appreciated. ...

Linking asynchronous AJAX requests using Angularjs

Currently in my AngularJS project, I have created a service with multiple functions that return promises. The AJAX Service I've Created: angular.module('yoApp') .factory('serviceAjax', function serviceAjax($http) { return ...

JavaScript array contains duplicate values

I have developed a custom Asp.Net user control. To keep things simple, I have omitted some of the HTML code. <asp:Panel ID="PanelInputControl" runat="server" CssClass="input-control input-period"> <div ID="InputWrapperMonth" runat="server" c ...

Add HTML content individually to each item in the array

I am currently developing a plugin and I need to load a preset in order to populate a form with the relevant data. In an attempt to write concise code, I created a variable called "template" that looks like this: var Fields = '<div c ...

Looking for a resolution with NicEditor - Seeking advice on incorporating custom select options

I recently started using NICInline Editor and found a helpful sample at Is there a way to incorporate custom options into this editor? I would like the selected option's value to be inserted right at the cursor point of the Editor Instance. Query: H ...

Utilize Javascript to refine JSON data strings

Currently, I am tackling a small project and facing a minor JS issue. The JSON string that I have looks like this: var jsObj = { "templates": { "form0": { "ID": "MyAlertNew", "isVisible": "true", ...

Transform ISO-8859-1 encoding into UTF-8

Recently, I encountered an issue while sending a HTTP request using jQuery's ajax. The server, unfortunately, returns the response in ISO-8859-1 format while my page is set to UTF-8. This discrepancy causes some characters to become unreadable. How ...

Ways to trigger Bootstrap modal through a PHP GET call

I have been searching for a solution to create a modal similar to this one, but I haven't found anything yet. My requirement is that when we pass true in a GET request, the modal should be displayed. Otherwise, if there is no value specified in the $ ...

"Enhance User Experience with jQuery Autocomplete using String Arrays

Within my web form model (AdtFormModel), there is a variable: public List<String> TemoinsVille { get; set; } I opted for a list structure as I intend to allow users to dynamically add more 'TemoinsVille' inputs in the form. Currently, ...

Tips for attaching a "progress" and refresh event to an ajax call while sending a file

I am currently using the FormData API and AJAX to upload files to a server in PHP-CodeIgniter. The file upload works perfectly when triggered by the file select event. However, I would like to display a progress bar next to each file being uploaded with th ...

Sorting functionality in Vuetify's DataTable

I am currently utilizing the features of Vuetify Data Tables and have set the following props: :options.sync="filter_values" @update:options="updateFilterValues()" The issue I am facing is that I want to disable sorting for certain col ...