在 Firebase 文档中找不到它,但是是否有像创建帐户时那样的密码更改监听器?
functions.auth.user().onCreate
Run Code Online (Sandbox Code Playgroud)
目标:向用户发送一封电子邮件,告知其密码已在 Web 应用程序中更改。
我正在使用以下代码将一个或多个文件上传到 Firebase 存储。上传完成后,downloadURL 会记录在控制台中。
当所有文件上传后,我想在 forEach 函数之外执行另一个函数。当所有上传任务完成后,如何打印控制台日志?
onSubmit = e => {
e.preventDefault();
const { files } = this.state;
files.forEach(file => {
const uploadTask = Storage.ref(`files/${file.name}`).put(file);
uploadTask.on('state_changed', snapshot => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(progress);
}, error => { console.log(error) }, () => {
uploadTask.snapshot.ref.getDownloadURL().then(downloadURL => {
console.log(downloadURL);
});
});
});
//Wait till all uploads are completed
console.log('all uploads complete');
}
Run Code Online (Sandbox Code Playgroud) 我有一个Array.map函数用于循环遍历新上传的文件.
由于用户可以多次上传文件,因此必须将文件一起添加到一个数组中.
因此我使用以下代码
onFileSelect = e => {
//FileList to array
const files = [...e.target.files];
files.map(file => {
this.setState({ invoices: [...this.state.invoices, file]})
});
}
Run Code Online (Sandbox Code Playgroud)
问题是只能在最后一项上执行setState.因此,如果一个nuser选择5个文件,只有最后一个文件进入该状态.
一个可能的解决方案是采用exesting数组,推送新文件并在map函数之外执行一个setState,但我想知道为什么或如何将多个setStates放到一个map函数中.
这很有效
onFileSelect = e => {
//FileList to array
const files = [...e.target.files];
const invoiceArr = this.state.invoices;
files.map(file => {
invoiceArr.push(file)
});
this.setState({invoices: invoiceArr});
}
Run Code Online (Sandbox Code Playgroud) 当在 vue 中添加vuex或vue-router作为插件并使用 options api 时,您可以使用关键字访问这些插件this。
main.js
import { createApp } from 'vue';
import i18n from '@/i18n';
import router from './router';
import store from './store';
app.use(i18n);
app.use(store);
app.use(router);
Run Code Online (Sandbox Code Playgroud)
随机组件.vue
<script>
export default {
mounted() {
this.$store.dispatch('roles/fetchPermissions');
},
}
</script>
Run Code Online (Sandbox Code Playgroud)
组合 api 中不再提供该this关键字,这会导致大量重复代码。要使用store,vue-router或i18n库,我必须导入并定义以下内容:
具有组合 api 的 RandomComponent.vue
<script setup>
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n'; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在父组件(创建用户表单)和子组件(可重用选择框)之间创建双向绑定。
父组件
<template>
<Selectbox :selectedOption="selectedRole" :options="roles" />
<span>SelectedRole: {{ selectedRole }}</span>
</template>
<script>
import Selectbox from '@/components/formElements/Selectbox.vue';
export default {
components: {
Selectbox,
},
async created() {
await this.$store.dispatch('roles/fetchRoles');
this.selectedRole = this.roles[0].value;
},
data() {
return {
selectedRole: null,
};
},
computed: {
roles() {
return this.$store.getters['roles/roles'].map((role) => ({
value: role.id.toString(),
label: role.name,
}));
},
},
};
</script>
Run Code Online (Sandbox Code Playgroud)
我将角色作为选项传递,并将 selectedRole 变量作为 selectedOption 传递。
子组件
<template>
<select :value="selectedOption" @input="(event) => $emit('update:selectedOption', event.target.value)">
<option v-for="option in options" :value="option.value" :key="option.value">{{ option.label }}</option>
</select> …Run Code Online (Sandbox Code Playgroud) 我有一个包含 360 万条记录的 Companies.json 文件(每条记录都包含一个 id 和增值税号)和一个包含 76.000 条记录(+- 20 个属性)的 event.json 文件。我编写了一个脚本,执行以下步骤:
该脚本运行良好,但需要 6-7 小时才能完成。有办法加快速度吗?
当前脚本
import json
counter = 0;
with open('companies.json', 'r') as companiesFile:
with open('events.json', 'r') as eventsFile:
events = json.load(eventsFile)
companies = json.load(companiesFile)
for index, event in enumerate(events):
print('Counter: ' + str(index))
if 'status' in event:
if(event['status'] == 'new'):
if 'companyID' in event:
for company in …Run Code Online (Sandbox Code Playgroud) firebase ×3
javascript ×2
reactjs ×2
vue.js ×2
python ×1
vue-i18n ×1
vue-router ×1
vuejs3 ×1
vuex ×1