在vue的src下新建文件夹untils,在untils下创建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);
然后就可以在各个页面中使用了