定义全局方法 在任意页面使用

在src下创建 untils文件夹,然后在他下面创建index.js文件
index.js是公共方法,任何页面都可以使用的哈

index.js

export default {
  install(Vue) {
    Vue.prototype.say = function() {
      alert("我是全局方法");
    };
  },
};

main.js

import way from "./utils";
Vue.use(way);

XXX.vue

this.say() 直接去调用这个方法
posted @ 2020-06-01 23:30  何人陪我共长生  阅读(368)  评论(0编辑  收藏  举报