篇首语:本文由小编为大家整理,主要介绍了vue中的then方法相关的知识,希望对你有一定的参考价值。
参考技术A .then((data)=> )里的data是指接口成功返回的数据,包含请求头,请求体,等信息;你可以打印下看看这个data,我们在jquery的success(obj)的obj类似于这里的data.data
这里的then()方法有两个参数,第一个是成功时的回调方法,默认给这个方法传递了成功的数据,
另一个是失败的方法,以及失败的数据,第二个可选,
then(function(obj)
,function(err)
)
箭头函数就是
then((data)=>
)
第二个参数省略了.
一般情况下,为了不报错,会在then()后面调用.catch(e)
//类似trycatch(e) 你可以理解为省略了try()
[Vue 警告]:v-on 处理程序中的错误:“TypeError: Object(...)(...).httpsCallable(...).then 不是函数”
【中文标题】[Vue 警告]:v-on 处理程序中的错误:“TypeError: Object(...)(...).httpsCallable(...).then 不是函数”【英文标题】:[Vue warn]: Error in v-on handler: "TypeError: Object(...)(...).httpsCallable(...).then is not a function" 【发布时间】:2021-12-04 15:57:30 【问题描述】:我正在尝试从我的 Vue 应用程序调用这个 firebase 云函数
exports.sayHi = functions.https.onCall((data, context) => return "hi";);
这是我在店里的动作
import getFirebaseDB, getFirebaseFunctions, from "../../helpers/firebase/authUtils";reserveApt() getFirebaseFunctions() .httpsCallable("sayHi") .then((result) => console.log(result); ); ,
这是我在 ../../helpers/firebase/authUtils 中的辅助函数:
import firebase from "firebase/app";import "firebase/auth";import "firebase/firestore";import "firebase/functions";/** * Initilize the backend * @param * config */const initFirebaseBackend = (config) => if (!_fireBaseBackend) _fireBaseBackend = new FirebaseAuthBackend(config); _db = firebase.firestore(); _functions = firebase.functions(); return _fireBaseBackend;;/** * Returns the firebase backend */const getFirebaseBackend = () => return _fireBaseBackend;;/** * returns firestore db */const getFirebaseDB = () => if (!_db) _db = firebase.firestore(); return _db;;/** * returns firebase functions */const getFirebaseFunctions = () => if (!_functions) _functions = firebase.functions(); return _functions;;export initFirebaseBackend, getFirebaseBackend, getFirebaseDB, getFirebaseFunctions,;
Firebase 已正确初始化,并且所有其他功能(如 auth 和 firestore)都可以正常工作,但是当我调用它时,会出现以下错误:
[Vue warn]: Error in v-on handler: "TypeError: Object(...)(...).httpsCallable(...).then is not a function"found in---> at src/views/pages/property/properties.vue at src/App.vue
【问题讨论】:
你可以试试这个solution 谢谢@AlanOmar 我刚刚想通了。但我不确定为什么这是解决方案。直接调用它似乎是合理的。 【参考方案1】:显然问题在于调用函数。我不得不这样称呼它:
var reserve = getFirebaseFunctions().httpsCallable("sayHi"); reserve().then((result) => console.log(result); );
但我不知道为什么!!
【讨论】:
以上是关于vue中的then方法的主要内容,如果未能解决你的问题,请参考以下文章