1
npm install xe-utils --save

vue2.x 中:

import Vue from 'vue'
import XEUtils from 'xe-utils'

Vue.prototype.$utils = XEUtils
Vue.prototype.$cookie = XEUtils.cookie

vue3.x 中:

import app from '../app'
import XEUtils from 'xe-utils'

app.config.globalProperties.$utils = XEUtils
app.config.globalProperties.$cookie = XEUtils.cookie

使用

<template>
  <div>{{ $utils.toDateString(startDate, 'yyyy-dd-MM HH:mm:ss') }}</div>
  <div>{{ endDate }}</div>
</template>
<template>
  <div>{{ $utils.toDateString(startDate, 'yyyy-dd-MM HH:mm:ss') }}</div>
  <div>{{ endDate }}</div>
</template>

<script>
export default {
  name: 'App',
  data: {
    return {
      name: this.$cookie('name'),
      startDate: new Date(),
      endDate: null
    }
  },
  created () {
    const type = this.$cookie('type')
    this.endDate = this.$utils.toDateString(new Date(), 'MM/dd/yyyy HH:mm:ss.SSS')
    console.log(`type=${type`)
  }
}
</script>

abc26296
172 声望24 粉丝