// main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import './directive/index.js'
import './filter/index.js'
import {
Message
} from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'
import 'element-ui/lib/theme-chalk/display.css'
import './assets/styles/reset.css'
import './assets/styles/border.css'
import './assets/styles/iconfont.css'
import App from './App'
import router from './router'
import axios from '../config/http'
import qs from 'qs';
import apiConfig from '../config/api.config'
import store from './store/store'
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.prototype.$http = axios
Vue.prototype.$baseUrl = apiConfig.baseUrl
// Vue.prototype.$qs = qs;
axios.defaults.baseURL = apiConfig.baseUrl
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
components: {
App
},
template: '<App/>'
})
filter
// filter/index.js
import Vue from 'vue'
import { formatDate } from '../assets/js/date.js'
Vue.filter('priceFloat', function(value) {
value = value.toString();
var result = Number(value).toFixed(2);
return result;
})
Vue.filter('shortString', function(value) {
value = value.toString();
if (value.length > 20) {
value = value.substr(0, 20).concat('...');
}
return value;
})
Vue.filter('propTime', function(value) {
let time = new Date(value)
return formatDate(time, 'yyyy-MM-dd hh:mm:ss')
})
Vue.filter('formatTime', function(value) {
// let time = new Date(value)
// return formatDate(time, 'yyyy-MM-dd hh:mm:ss')
let now = new Date().getTime()
let differ = (now - value) / 1000 //转化成秒
if (differ < 60) {
return Math.floor(differ) + ' 秒前'
} else if (differ / 60 < 60) {
return Math.floor(differ / 60) + ' 分钟前'
} else if (differ / 3600 < 24) {
return Math.floor(differ / 3600) + ' 小时前'
} else if (differ / 3600 / 24 < 30) {
return Math.floor(differ / 3600 / 24) + ' 天前'
} else {
let time = new Date(value)
return formatDate(time, 'yyyy-MM-dd')
}
})