search
HomeWeb Front-endJS TutorialSolve the problem of query dynamic parameter passing in vue-router

Below I will share with you an article that solves the problem of query dynamic parameter transmission in vue-router. It has a good reference value and I hope it will be helpful to everyone.

I have been writing a project recently. In the process of writing the project, I always find problems of one kind or another. For example, how does the query in vue-router pass dynamic parameters? After some twists and turns, the problem was solved. The problem is described as follows:

I hope the url will be like this when jumping: http://localhost:8080/editmovie?id=****

<li><router-link :to="{path:&#39;editmovie&#39;, query: {id : 111}}" class="edit">修改</router-link></li>

But what? The above is just a static one, the url will always be: http://localhost:8080/editmovie?id=111

In fact, the id I need is placed in a hidden element in:

<li class="hiden">2016987</li>

At first, my idea was to call the methods in the components, but I tried several times. , all failed. Then I accidentally saw a question and answer

vue-router dynamic configuration of incoming parameters, and then I saw the following code:

<li v-for=" el in hotLins" >
 <router-link :to="{path:‘details‘,query: {id:el.tog_line_id}}">
  <img  src="/static/imghwm/default1.png"  data-src="el.image_list[0]"  class="lazy"  : alt="Solve the problem of query dynamic parameter passing in vue-router" >
  <h3 id="el-tourism-name-nbsp-el-tog-line-id">{{el.tourism_name}} {{el.tog_line_id}}</h3>
  <p>{{el.address}}</p>
 </router-link>
</li>

I suddenly feel like I have an idea. The solution is as follows:

Bind the id of li in data id, and then write the bound one in the query

<li v-bind:id="id"><router-link :to="{path:&#39;editmovie&#39;, query: {id : id}}" class="edit">修改</router-link></li>

export default {
 name : &#39;Movie&#39;,
 data() {
 return {
  id : ""
 }
 },
 methods: {
 getId () {
  var id = $(&#39;.hiden&#39;).eq(0).text();
  console.log(id);
 }
 },
 mounted() {
 this.id = $(&#39;.hiden&#39;).eq(0).text();
 },
 components : {
 Heade,
 Foot
 }
}

Then the url will change It looks like this: http://localhost:8080/editmovie?id=2016987, and the problem is solved.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Ajax method of sending and receiving binary byte stream data

Use Ajax technology to achieve partial refresh Product quantity and total price example code

Perfectly solves the problem of Session failure during ajax access

##

The above is the detailed content of Solve the problem of query dynamic parameter passing in vue-router. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Vue应用中遇到vue-router的错误“NavigationDuplicated: Avoided redundant navigation to current location” – 怎么解决?Vue应用中遇到vue-router的错误“NavigationDuplicated: Avoided redundant navigation to current location” – 怎么解决?Jun 24, 2023 pm 02:20 PM

Vue应用中遇到vue-router的错误“NavigationDuplicated:Avoidedredundantnavigationtocurrentlocation”–怎么解决?Vue.js作为快速而灵活的JavaScript框架在前端应用开发中越来越受欢迎。VueRouter是Vue.js的一个代码库,用于进行路由管理。然而,有时

一文深入详解Vue路由:vue-router一文深入详解Vue路由:vue-routerSep 01, 2022 pm 07:43 PM

本篇文章带大家详解Vue全家桶中的Vue-Router,了解一下路由的相关知识,希望对大家有所帮助!

如何通过拖放在Power Query中对多列进行重新排序如何通过拖放在Power Query中对多列进行重新排序Mar 14, 2024 am 10:55 AM

在这篇文章中,我们将向你展示如何通过拖放在PowerQuery中对多列进行重新排序。通常,从各种来源导入数据时,列可能不是所需的顺序。重新排序列不仅允许您按照符合您的分析或报告需求的逻辑顺序排列它们,还可以提高数据的可读性,并加快过滤、排序和执行计算等任务。如何在Excel中重新排列多个列?在Excel中,重新排列列的方法有多种。您可以简单地选择列标题,然后将其拖动到所需位置。但是,当处理包含许多列的大表时,这种方法可能会变得繁琐。为了更高效地重新排列列,您可以使用增强查询编辑器。通过增强查询编

在Vue应用中使用vue-router时出现“Error: Avoided redundant navigation to current location”怎么解决?在Vue应用中使用vue-router时出现“Error: Avoided redundant navigation to current location”怎么解决?Jun 24, 2023 pm 05:39 PM

在Vue应用中使用vue-router时,有时候会出现“Error:Avoidedredundantnavigationtocurrentlocation”的错误信息。这个错误信息的意思是“避免了到当前位置的冗余导航”,通常是因为重复点击了同一个链接或者使用了相同的路由路径导致的。那么,怎么解决这个问题呢?使用exact修饰符在定义router

Vue-Router: 如何使用路由元信息来管理路由?Vue-Router: 如何使用路由元信息来管理路由?Dec 18, 2023 pm 01:21 PM

Vue-Router:如何使用路由元信息来管理路由?简介:Vue-Router是Vue.js官方的路由管理器,它可以帮助我们快速构建单页应用程序(SPA)。除了常见的路由功能外,Vue-Router还支持使用路由元信息来管理和控制路由。路由元信息是可以附加到路由上的自定义属性,它可以帮助我们实现一些特殊的逻辑或者权限控制。一、什么是路由元信息?路由元信息是

React Query 数据库插件:实现数据导入和导出的方法React Query 数据库插件:实现数据导入和导出的方法Sep 26, 2023 pm 05:37 PM

ReactQuery数据库插件:实现数据导入和导出的方法,需要具体代码示例随着ReactQuery在前端开发中的广泛应用,越来越多的开发者开始使用它来管理数据。而在实际开发中,我们经常需要将数据导出到本地文件或从本地文件导入数据到数据库中。为了更方便地实现这些功能,可以使用ReactQuery数据库插件。ReactQuery数据库插件提供了一系列方

在Vue应用中使用vue-router时出现“Error: Failed to resolve async component: xxx”怎么解决?在Vue应用中使用vue-router时出现“Error: Failed to resolve async component: xxx”怎么解决?Jun 24, 2023 pm 06:28 PM

在Vue应用中使用vue-router是一种常见的方式来实现路由控制。然而,在使用vue-router的时候,有时候会出现“Error:Failedtoresolveasynccomponent:xxx”的错误,这是由于异步组件加载错误导致的。在本文中,我们将探讨这个问题,并提供解决方案。理解异步组件加载原理在Vue中,组件可以被同步或异步地创建

在Vue应用中使用vue-router时出现“Error: Invalid route component: xxx”怎么解决?在Vue应用中使用vue-router时出现“Error: Invalid route component: xxx”怎么解决?Jun 25, 2023 am 11:52 AM

Vue是一个流行的前端框架,它允许开发者快速构建高效、可重用的web应用程序。Vue-router是Vue框架中的一个插件,可以帮助开发者轻松管理应用的路由和导航。但是,在使用Vue-router的过程中,有时候会遇到一个常见的错误:“Error:Invalidroutecomponent:xxx”。这篇文章将介绍这个错误的原因和解决方法。原因在Vu

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),