当我键入 'npm run serve' 时出现 SyntaxError。错误是:意外的标记,应为“,” (45:2)。我究竟做错了什么?

I get a SyntaxError when I type 'npm run serve'. The error is: Unexpected token, expected "," (45:2). What am I doing wrong?

我在键入时收到 SyntaxError:npm run serve

错误是:Unexpected token, expected "," (45:2)

我做错了什么?

我在 Visual-Studio-Code 中使用 Pusher 和 Vue.js。

这是来自网站的教程:https://www.sitepoint.com/pusher-vue-real-time-chat-app/

下面是我的代码。请大家帮帮我!!

    <template>
  <div class="login-form">
    <h5 class="text-center">Chat Login</h5>
    <hr>
    <b-form @submit.prevent="onSubmit">
       <b-alert variant="danger" :show="hasError">{{ error }} </b-alert>

      <b-form-group id="userInputGroup"
                    label="User Name"
                    label-for="userInput">
        <b-form-input id="userInput"
                      type="text"
                      placeholder="Enter user name"
                      v-model="userId"
                      autocomplete="off"
                      :disabled="loading"
                      required>
        </b-form-input>
      </b-form-group>

      <b-button type="submit"
                variant="primary"
                class="ld-ext-right"
                v-bind:class="{ running: loading }"
                :disabled="isValid">
                Login <div class="ld ld-ring ld-spin"></div>
      </b-button>
    </b-form>
  </div>
</template>

// something after .env


<script>
import { mapState, mapGetters, mapActions } from 'vuex'

export default {
  name: 'login-form',
  data() {
    return {
      userId: '',
    }
  }
  methods: {
    ...mapActions ([
      'login'
    ]),
    async onSubmit() {
      const result = await this.login(this.userId);
      if(result) {
        this.$router.push('chat');
      }
    }
  }
  computed : {
    isValid: function(){
      const result = this.userId.length < 3;
      return result ? result : this.loading
    },
    ...mapState([
      'loading'
      'error'      
    ]),
    ...mapGetters([
      'hasError'
    ])
  }
}

</script>

您的对象中缺少一些逗号。 Javascript 对象键之间需要逗号。

let object = {
  key: "value",
  otherKey: "otherValue"
}

注意 "value" 之后的 ,

您要导出的对象在 datamethods 键后没有逗号,即使后面有其他键也是如此。

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics