1.在plugins的文件夹地下去建立一个proto.js的文件

import Vue from 'vue'
var test = {
    install(Vue) {
        Vue.prototype.test = {
            val: function(val) {
                console.log(9999);
            }
        };
        Vue.prototype.testname = '周欢'
    }
}
Vue.use(test)

2.直接使用

 created() {
    console.log(this.$route.params, 'this.$route');  
    console.log(this.testname, 'this'); //全局去拿字符串
  },
  mounted() {
    this.test.val()  //全局去调用事件
  }

在created里面去调用事件会报错

posted on 2020-03-23 16:40  周小姐你好  阅读(4707)  评论(0编辑  收藏  举报