const startDate = new Date(new Date() - 24 * 60 * 60 * 1000 * 30)
const endDate = new Date()
const dataText = ‘’//表格置空
export default {
startDate,
endDate,
dataText,
}
全局使用,示例如下:
import globalVariable from ‘./assets/js/global_variable’
Vue.prototype.GLOBAL = globalVariable
在需要使用的模块文件中使用(无需引入,直接通过`this`使用),示例如下:
data() {
return {
startDate: this.GLOBAL.startDate, //开始时间
endDate: this.GLOBAL.endDate, //结束时间
dataText: this.GLOBAL.dataText, //表格开始置空
};
},
注⚠️:务必以`$`开头,否则会命名冲突!
### 三、全局挂载全局函数
有很多函数在重复使用,所以,我们可以对这些函数进行全局挂载,省时又省力!
实现过程如下:
>
> 1. 单独新建一个全局变量模块文件,模块中定义一些变量初始状态,用`export default` 暴露出去;
> 2. 在`main.js`中引入&