Encapsulation of vue obtaining parameter method
The parameters in the url can be obtained using this.$
- 1. Define public methods and expose them
// Get the parameters that are redirected natively//Usage method: 1. Defined method in commonjs 2. Introduced and registered for prototype 3. Page useexport function GetRequest() { let url = ("?")[1].split("&"); //Get the string after the "?" character in the url (url); let query = {}; (item => { query[("=")[0]] = decodeURIComponent(("=")[1]); //Transcoding }); return query; }
- 2. The prototype introduced and registered with the Vue instance
// Get the parameters of splicing in the urlimport { GetRequest } from "./common/js/"; = GetRequest;
- 3. Called on the page
mounted() { (); }
vue encapsulation global method
Method one
- 1. Packaging
const util = { getCookie:()=>{ return null; } } = util;
- 2. Call
import util from '../assets/js/' ();
Method 2
- 1. Packaging
export function getCookie(){ return null; } export function setCookie(){ return null; }
- 2. Call
import { getCookie,setCookie } from '../assets/js/' getCookie(); setCookie();
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.