how can i get json object data in my url in vuejs

xander

i have this json object

    blog:{
      "_id": "62567252370e769a8a93a517", 
      "title": "my trip to zanziar"
    }

i'm trying to show in my url

http://localhost:8082/blog/my-trip-to-zanziar

in my url

but i'm getting

http://localhost:8082/blog/my%20trip%20to%20zanziar

and its not displaying any data

this is how i go to the route

 <router-link :to="`/blog/${blog._title}`">
                
                </router-link>

this is my router

  {
    path: "/blog/:title",
  },

this is how i diplay to get the details under the title

mounted() {
    axios
      .get(`http://localhost:4000/api/blogs/${this.$route.params.title}`, {})
      .then(response => {
        console.log(response);
        this.blog = response.data.blog;
      })
      .catch(error => {
        console.log(error);
      });
  }

please how i can go about this

yoduh

use String.prototype.replaceAll() where appropriate to replace empty spaces with hyphens:

 <router-link :to="`/blog/${blog?._title?.replaceAll(' ', '-')}`" />

You might also consider making the formatted string it's own computed property if you need to perform the replacement more than once in your component.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can i loop the response of my JSON Object?

How can I get simple data from JSON object

How can I check if my response is a string or JSON Object?

How can I get my list passed by url?

How can I translate my routes with VueJS?

How can I add data to a Kotlin object and get it on a Vuejs page

With vuejs, how do I get firebase (vuefire) object into component data

How can I get one object data from my Firebase by ref

How can I get JSON data from a URL using PHP? I'm getting authentication failure

How can I display my json object with TypeScript in Angular?

How can I get {% url logout %} to work in my Django template?

How can i get json object results in php using php_decode and url

How can I get the URL of my image in Picasso

How can I return a common JSON object in my flask API?

How can I get a specific value from my JSON object without using Array.filter()?

How do I get the JSON data in my MVC controller, when I dont know the JSON object name?

how can i save data, retrieved from a url into my database

How can I access my JSON object?

how do I get the corresponding JSON value in my JSON object?

How can I get data from JSON array object with JQUERY?

How to get data (of my api json) in my object ( Redux, React )?

how i can get data from Json object and array

How can I get json data from a url using this.$http.get()?

How can i get my url parameter right on Javascript?

How can I fix my code to make it send the json data as a response to postman's GET requests?

How can I get 1 array contains many object to create a JSON file from my code?

how can i get the details of my current product.id in my browser url using vuejs

how can i encode a token in my url using vuejs

How can I create my data class for my json file?