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 { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

const app = createApp(App)

// 全局挂载
app.config.globalProperties.$utils = XEUtils
app.config.globalProperties.$cookie = XEUtils.cookie

app.use(store).use(router).mount('#app')

使用

<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 () {
    this.$cookie('name', 'test1')
    this.endDate = this.$utils.toDateString(new Date(), 'MM/dd/yyyy HH:mm:ss.SSS')
    console.log(`endDate=${this.endDate`)
  }
}
</script>

 

Logo

前往低代码交流专区

更多推荐