- 在 src/utils/index.js 编写文件,可以是公共的函数
export default {
getThisMonth() {
const myDate = new Date();
const thisyear = myDate.getFullYear();
const thismonth = myDate.getMonth() + 1;
return `${thisyear}-${thismonth}-01`;
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 在main.js中绑定函数方法
// 引用工具文件
import utils from './utils/index.js'
// 将工具方法绑定到全局
Vue.prototype.$utils = utils
1
2
3
4
2
3
4
使用函数
$utils.函数名
1
2
2