Javascript Vue+;Firebase:忽略函数useEmulator()
我在Javascript Vue+;Firebase:忽略函数useEmulator(),javascript,firebase,vue.js,google-cloud-functions,firebase-tools,Javascript,Firebase,Vue.js,Google Cloud Functions,Firebase Tools,我在firebase.functions().useEmulator('localhost',5001)中找到了这行代码,该代码假定将您的Vue应用程序指向本地运行的模拟器,但出于某种原因,我的项目忽略了这行代码,并继续调用远程部署的函数 下面是我的@/plugins/firebase.js的相关部分: import firebase from 'firebase/app'; import 'firebase/functions'; firebase.initializeApp({ api
firebase.functions().useEmulator('localhost',5001)
中找到了这行代码,该代码假定将您的Vue应用程序指向本地运行的模拟器,但出于某种原因,我的项目忽略了这行代码,并继续调用远程部署的函数
下面是我的@/plugins/firebase.js
的相关部分:
import firebase from 'firebase/app';
import 'firebase/functions';
firebase.initializeApp({
apiKey: process.env.VUE_APP_FIREBASE_API_KEY,
authDomain: process.env.VUE_APP_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.VUE_APP_FIREBASE_DATABASE_URL,
projectId: process.env.VUE_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.VUE_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.VUE_APP_FIREBASE_MESSAGE_SENDER_ID,
appId: process.env.VUE_APP_FIREBASE_APP_ID,
measurementId: process.env.VUE_APP_FIREBASE_MEASUREMENT_ID
});
firebase.functions().useEmulator('localhost', 5001);
const func = {
botcheck: firebase.app().functions('europe-west2').httpsCallable('validateRecaptcha'),
};
export { func };
然后要调用botcheck函数,我将在Vuex操作中运行以下命令:
const fb = require('@/plugins/firebase');
...
await fb.func.botcheck();
我做错了什么?如何让它正确指向本地运行的模拟器
Vue项目版本:
- vue:2.6.11
- 火基:8.3.2
- firebase管理员:9.2.0
- firebase功能:3.11.0
如果需要包含其他信息,请告诉我。这是您的代码,因为我确保已使用Firebase Emulator的云函数正确配置了
useEmulator()
。请随意尝试:
import firebase from 'firebase/app';
import 'firebase/functions';
const firebaseConfig = {
// Your config
};
const app = firebase.initializeApp(firebaseConfig);
const functions = app.functions('europe-west2');
functions.useEmulator('localhost', 5001);
const func = {
botcheck: functions.httpsCallable('validateRecaptcha'),
};
export { func };
这是您的代码,我确保使用Firebase Emulator的云函数正确配置了
useMulator()
。请随意尝试:
import firebase from 'firebase/app';
import 'firebase/functions';
const firebaseConfig = {
// Your config
};
const app = firebase.initializeApp(firebaseConfig);
const functions = app.functions('europe-west2');
functions.useEmulator('localhost', 5001);
const func = {
botcheck: functions.httpsCallable('validateRecaptcha'),
};
export { func };
这一行:
firebase.functions()
是:
在当前代码中,将未指定区域的函数连接到仿真器。由于使用时将区域指定为europe-west2
,因此需要将europe-west2
功能连接到仿真器。您可以通过更改此行来执行此操作:
firebase.functions().useEmulator('localhost', 5001);
要使用正确的区域,请执行以下操作:
firebase.app().functions('europe-west2').useEmulator('localhost', 5001)
附加说明:而firebase.functions()
和firebase.app().functions()
返回对象的相同实例(连接到us-central1
区域),firebase.app().functions('us-central1')
(在区域中传递)返回对象的不同实例。您需要将使用的每个实例连接到模拟器。此行:
firebase.functions()
是:
在当前代码中,将未指定区域的函数连接到仿真器。由于使用时将区域指定为europe-west2
,因此需要将europe-west2
功能连接到仿真器。您可以通过更改此行来执行此操作:
firebase.functions().useEmulator('localhost', 5001);
要使用正确的区域,请执行以下操作:
firebase.app().functions('europe-west2').useEmulator('localhost', 5001)
附加说明:而
firebase.functions()
和firebase.app().functions()
返回对象的相同实例(连接到us-central1
区域),firebase.app().functions('us-central1')
(在区域中传递)返回对象的不同实例。您需要将使用的每个实例连接到模拟器。。谢谢,真是天才。谢谢