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

文章目录

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


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>

你可能感兴趣的:(Vue框架,javascript,vue.js,开发语言)