在vue的src下新建文件夾untils,在untils下創(chuàng)建index.js文件
index.js文件代碼
export default {
install(Vue){
Vue.prototype.GetRequestSearchStr = function(url) {
var theRequest = new Object();
if (url.indexOf("?") != -1) {
let str = url.substr(url.indexOf("?")+1);
let strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
}
}
main.js文件加上以下代碼
import untils from "./untils/index";
Vue.use(untils);
然后就可以在各個(gè)頁面中使用了