在工作中需求是这样的:2020-10-10
但是后台给我的数据是这样的:2020-10-10 14:04:37
新建一个js文件写入:
import Vue from 'vue'
Vue.filter('filterTime', function(t, s) {
let time = new Date(t)
let y = time.getFullYear()
let m = time.getMonth() + 1
let d = time.getDate()
return y + s + m + s + d
})
然后在需用到的地方引入:import “…/assets/js/filter”
time:new Date()
<el-button type="primary" @click="hangLL">生成二维码{{time}}</el-button>
<el-button type="primary" @click="hangLL">生成二维码{{time | filterTime('/')}}</el-button>
<el-button type="primary" @click="hangLL">生成二维码{{time | filterTime('-')}}</el-button>
效果如下: