undefinedfix
Sign in

Vue creates a global function and calls it, always reporting an error. Besides this method, is there any other way to create a local component

BKS edited in Thu, 13 Oct 2022
3 Replies
miyaqq
commented on Thu, 13 Oct 2022

Does your so-called global function depend on Vue m?

If you don't rely on it, save a separate file for export and import where you need it.

faza
commented on Fri, 14 Oct 2022

Where is this method written?

Did you import Vue?

import Vue from 'vue'
MichaelE
commented on Fri, 14 Oct 2022

//Global approach

Api = {
  // 支付方式
  GetPayType: function (tyep) {
    tyep = tyep * 1
    switch (tyep) {
      case 0:
        return '试听'
        break
      case 1:
        return '微信'
        break
      case 2:
        return '支付宝'
        break
      case 3:
        return '银行卡'
        break
      case 4:
        return '现金'
        break
    }
  },
}
export default Api

// main.js

// 注册全局方法
import Api from "./utils/api";  
Vue.prototype.$api = Api; // 方法

//Use in build

this.$api.GetPayType()
lock This question has been locked and the reply function has been disabled.