0
点赞
收藏
分享

微信扫一扫

vue 全局引用dayjs(笔记)

萍儿的小确幸 2022-03-27 阅读 17

1、main.js引用

import Vue from 'vue'
import App from './App.vue'
import word from '@/components/Word'

import axios from "axios";
import day from "dayjs";

Vue.prototype.axios=axios;
Vue.prototype.dayjs=day;

Vue.component('MyWord',word)
Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

2、组件调用

  sub() {
        let dayjs = this.dayjs;//不能在方法返回中直击使用this.dayjs
        this.axios.get("http://localhost:8082/user/" + this.name).then(function (rst) {
          console.log(dayjs(rst.data.times).format('YYYY.MM.DD'))
        });
      },
举报

相关推荐

0 条评论