Vue 全局方法封装,以log为例

image.png

新建js文件

var fun = function (info) {
  console.log('hello -> '+info)
}
export default fun

main.js导包并挂载

import log from './common/common.js'
Vue.prototype.$log = log

使用

this.$log('android created')

你可能感兴趣的:(Vue 全局方法封装,以log为例)