使用全局过滤器

使用原型属性

main.js
import Moment from 'moment'
import Antd, { Modal } from 'ant-design-vue'

Vue.filter('formatDate', function (value) {
  return Moment(value).format('YYYY-MM-DD HH:mm:ss')
})

Vue.use(Antd)
Vue.prototype.$confirm = Modal.confirm

组件template中可以使用管道符【|】,js中可以如此使用

this.$options.filters.formatDate(val)

打包

产品模式去掉console

  • webpack (webpack.conf.js)
npm i -D uglifyjs-webpack-plugin
//在webpack配置文件里
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
plugins:[
...

new UglifyJsPlugin({
    uglifyOptions:{
        compress:{
            drop_console:true
        }
    },
    sourceMap:true,
    parallel:true    

})
...

]
  • vue cli (vue.config.js)
    if (process.env.NODE_ENV === 'production') {
      // production development
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
...

table前端筛选

onFilter: (value: string, record: TableDataType) => value ?record.name.indexOf(value) === 0 : record.name === '',