main.js中操作

先import需要挂载的方法

然后通过vue.prototype 去全局装载

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Cookies from 'js-cookie'

import './assets/icons' // icon
// import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/ruoyi";

import Pagination from "@/components/Pagination";
// 自定义表格工具扩展
import RightToolbar from "@/components/RightToolbar"
// 头部标签插件
import VueMeta from 'vue-meta'

/**
 * dev001 ,这里可以只引入部分组件,参考https://mp.csdn.net/mp_blog/creation/editor/119744136
 */
import Element from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
/**
 * dev001 这里可以参考开源框架对element样式进行封装,后续可以研究下
 */
import './assets/styles/element-variables.scss'
import '@/assets/styles/index.scss' // global css
import '@/assets/styles/ruoyi.scss' // ruoyi css


/**
 * dev001 全局方法挂载
 * 全局挂载的方法在vue的任意位置都可以用 this.方法名来调用
 */
Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree

// 全局组件挂载
Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar)
Vue.use(VueMeta)

Vue.config.productionTip = false

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

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

Logo

前往低代码交流专区

更多推荐