当前位置: 首页 > 工具软件 > total.js > 使用案例 >

【vue】main.js中全局挂载方法、组件:

农永宁
2023-12-01


1、全局挂载方法(公共工具方法、api接口方法):

【1】引入文件:

import { getDict } from "@/api/common/index";
import { parseTime, resetForm } from "@/utils/util";


// 全局方法挂载
Vue.prototype.getDict = getDict
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm

【2】使用this.+方法名

this.getDict().then(res=>{
	...
})
2、全局挂载组件:

【1】引入文件:

// 分页组件
import Pagination from "@/components/Pagination";

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

【2】使用

页面内不需要再次引入和注册了

<template>
	...
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    ...
   </template>
 类似资料: