vue 客户端调用h5的方法

320 阅读1分钟

/src/utils/index.js


function andrewMethod(name, callback) {
  window[name] = callback;

}
module.exports = {
      andrewMethod
}
mounted() {
    //将要给客户端调用的方法挂载到 window 上,mes为客户端返回的参数
    andrewMethod("方法名[h5自己定]"), (mes) => {
      this.方法名(mes);
    };
},
methods: {
 // 客户端调用此方法,current_step为客户端返回的参数
     方法名(mes) {
      if (mes) {
        this.$router.push("/路由");
      }
    },
}