Vue 定义公共方法

  • 定义的公共方法

export default {
    install(Vue) {
        Vue.prototype.showErrMeg = function (msg) {
            this.$message({
                showClose: true,
                message: msg,
                type: 'error'
            });
        };
        Vue.prototype.showSuccessMeg = function (msg) {
            this.$message({
                showClose: true,
                message: msg,
                type: 'success'
            });
        };
    }
}

  • 调用示例:this.showErrMeg(xxx)
  • main.js引入
import comFun from './comfun/index';
Vue.use(comFun);

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。