v-on处理程序中的错误:“错误:Reference.set失败:第一个参数包含未定义”

时间:2019-06-12 16:41:13

标签: javascript firebase vue.js firebase-realtime-database

在哪里发生吹气错误?我已经凝视了一段时间,无法弄清楚。我试图控制台日志,所有被估算到数据库中的数据都具有值...

enter image description here

我正在尝试将当前消息推送到数据库,以便创建实时聊天应用程序。下面提供的代码。

该项目正在使用Firebase和VueJs。

CreateMessage.vue(我认为错误在哪里)

Conda

ChatRoom.vue。 (视图)

<template>
    <div class="container" style="margin-bottom: 30px">
        <form>
            <div class="form-group">
                <input type="text" class="form-control" placeholder="Enter message ..." v-model="newMessage">
                <p class="text-danger" v-if="errorText">{{ errorText }}</p>
            </div>

            <button class="btn btn-primary" type="submit"  @click.stop.prevent="createMessage"> Submit</button>
        </form>
    </div>
</template>

<script>
    import firebase from '../components/firebaseconfig';
    import AuthMonitor from '../AuthMonitor';
    import Login from '../components/Login';

    export default {
        name: 'CreateMessage',
        mixins:[AuthMonitor],
        data(){
            return {
                newMessage: "",
                errorText: "",
                user: firebase.auth().currentUser
            }
        },
        methods: {
            createMessage () {
                console.log(this.newMessage);
                if (this.newMessage != '') {
                    console.log(Date.now());
                    firebase.database().ref("messages").push().set({
                        message: this.newMessage,
                        name: this.user,
                        timestamp: Date.now()
                }).catch(err => {
                        console.log(err);
                    });
                this.newMessage = "";
                this.errorText = "";
                } else {
                    this.errorText = "A message must be entered!"
                }
            }
        }
    }
</script>

1 个答案:

答案 0 :(得分:1)

错误消息告诉您 this.esService.search(JSON.stringify(query)).subscribe(response => { let temp; this.esResponse = response; let result = this.esResponse.hits.hits; return from(result).pipe( concatMap(item => this.productService.getProductById(this.schemaId, item['_source']['consensusAssessmentId']).pipe( map(resp => { const answers = resp['answers']; const meets_count = answers.reduce((acc, cur) => cur.value === "Meets" ? ++acc : acc, 0); const needs_count = answers.reduce((acc, cur) => cur.value === "Needs Improvement" ? ++acc : acc, 0); item['_source']['meets'] = meets_count.toString(); item['_source']['needs'] = needs_count.toString(); }) )) ).subscribe(resp => { temp = resp; this.rows = temp.map( this.esService.convertToPE ); }) }) 包含属性 this.esService.search(JSON.stringify(query)).subscribe(response => { let temp = []; this.esResponse = response; let result = this.esResponse.hits.hits; result.forEach(item => { this.productService.getProductById(this.schemaId, item['_source']['consensusAssessmentId']).subscribe(resp => { const answers = resp['answers']; const meets_count = answers.reduce((acc, cur) => cur.value === "Meets" ? ++acc : acc, 0); const needs_count = answers.reduce((acc, cur) => cur.value === "Needs Improvement" ? ++acc : acc, 0); item['_source']['meets'] = meets_count.toString(); item['_source']['needs'] = needs_count.toString(); }) temp.push(item); }) this.rows = temp.map( this.esService.convertToPE ); }); ,该属性包含未定义的值。您不能将未定义的值放入实时数据库。