vue-cli定义全局变量
1:直接在main.js里往vue原型对象上添加
Vue.prototype.getTitle = {
title:'',
isBack: true,
isAdd: false,
};
Vue.prototype.baseUrl = function () {
return 'http://youkuaiyun.com';
};
复制代码
2:将js文件里的内容定义为全局
(1)config.js文件里
export default {
install(Vue,options)
{
Vue.prototype.baseUrl = function () {
return '111';
};
Vue.prototype.getTitle = {
title:'',
isBack: true,
isAdd: false,
};
Vue.prototype.showFootTab = {
isShow:false,
active:0,
}
}
}
(2) main.js 里
import config from './lib/config/config.js'
Vue.use(config);
使用时直接this.getTitle即可使用
3:
(1) js文件里
export const myObj={
name:"哈哈"
}
(2) main.js里
import {myObj} from "js"
Vue.use('myObj')