vue如何让自定义函数挂到全局

在main.js里进行全局注册

Vue.prototype.ajax = function (){}

在所有组件里可调用

this.ajax
实例main.js
Vue. prototype. ChangeDateFormat = function ( row, column){
// ChangeDateFormat(row, column) {
// var jsondate = row[column.property];
var jsondate = row[ column. property];
jsondate = jsondate. replace( "/Date(", ""). replace( ")/", "");
if ( jsondate. indexOf( "+") > 0) {
jsondate = jsondate. substring( 0, jsondate. indexOf( "+"));
} else if ( jsondate. indexOf( "-") > 0) {
jsondate = jsondate. substring( 0, jsondate. indexOf( "-"));
}
var date = new Date( parseInt( jsondate, 10));
var month = date. getMonth() + 1 < 10 ? "0" + ( date. getMonth() + 1) : date. getMonth() + 1;
var currentDate = date. getDate() < 10 ? "0" + date. getDate() : date. getDate();
var hour = date. getHours() < 10 ? "0" + date. getHours() : date. getHours();
var minutes = date. getMinutes() < 10 ? "0" + date. getMinutes() : date. getMinutes();
var second = date. getSeconds() < 10 ? "0" + date. getSeconds() : date. getSeconds();
return date. getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + minutes + ":" + second;
}
index.vue
< el-table-column prop= "last_time" :formatter=" this. ChangeDateFormat" width= "200px" align= "center" label= "登陆时间" > el-table-column >

你可能感兴趣的:(vue)