nuxt.js全局方法的使用


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里面去调用事件会报错


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM