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