1、新建插件文件Plugins.js:
export default {
install(Vue) {
Vue.prototype.$const = {
URL: "http://www.fly63.com/",
}
Vue.prototype.$utils = {
getUrlParam: function (name) {
var reg = new RegExp('(^|&?)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.href.substr(1).match(reg);
if (r != null) {
return decodeURI(r[2]);
}
return undefined;
}
}
}
}
2、main.js入口函数,配置如下:
import Plugins from './assets/js/Plugins.js'
Vue.use(Plugins)
3、在组件中的使用:
created: function () {
console.log(this.$const.URL);
var name = this.$utils.getUrlParam('name');
}