VUE+WEBPACK+VUE-CLI get URL Address parameter

Source: Internet
Author: User

In the absence of the use of Webpack+vue router development, want to get the Rul pass the parameter address, directly through a function can be obtained.

For example, in a www.test.com/test.html?sign=test address, to get the value of sign, the usual method is to use a function,

var geturlstr = function (name) {
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");
var r = window.location.search.substr (1). Match (REG);
if (r! = null) return unescape (r[2]);
return null;
}

var sign = geturlstr ("sign");

The value of sign is test;

So the problem, with router development, is directly through the route to jump page, then how to get it?

The first thought is also obtained through the above method, but tried, said not feasible. Through Baidu learned that can be directly used to provide the method;

As such, it is the same as the HTTP://LOCALHOST:8080/#/ONE?SIGN=NSRJBXX

var sign = this. $route. Query.sgin;

This refers to the Vue object, so it can be used directly in the Vue method, and sign is the parameter, which is customizable.

Understand very diving, simple can achieve the purpose, have a deeper understanding welcome to comment!!!

VUE+WEBPACK+VUE-CLI get URL Address parameter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.