首页 > 其他 > 详细

11 vue 自定义全局方法

时间:2020-06-12 20:50:08      阅读:38      评论:0      收藏:0      [点我收藏+]
//global.js
//
定义vue 全局方法 export default { install(Vue, options = {}) { Vue.prototype.$fn1 = function () { console.log(this); //this vue实例对 console.log(‘f1‘) } Vue.prototype.$fn2 = function () { console.log(‘fn2‘); console.log(this); } } }

2.main.js文件注入

// 定义全局方法
import global from ‘./utils/global‘
Vue.use(global)

3.use

handleCommand(command) {
      if (command === "aboutme") {
         this.$fn1()
         this.$fn2()
      } 
    },

 

11 vue 自定义全局方法

原文:https://www.cnblogs.com/xiaoliziaaa/p/13109979.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!