当我在模板中出于显示目的使用/操纵Vue.js时,为什么我的变量未定义?

问题描述 投票:0回答:1

我具有以下vue组件:

<template>
  <grid :data="comments>
  </grid>
<template>

<script>
  import Grid from '/@components/Grid';
  import { mapstate, mapgetters } from "vuex";

  export Default {
    name: Comments,
    components: {Grid},
    computed: {
      ...mapState("state", ["review"]),
      ...mapGetters("state", ["getComments"]),

      comments() {
        // the lines below log and execute successfully when they're 
        // the only lines in the method.
        console.log(this.getComments);
        let objArray = this.getComments;
        console.log(objArray);

        // but when I add a loop to go through the data, 
        // and append a string all of a sudden  
        // variables are undefined? and the lines above dont print
        for (var i =0; i < objArray.length; i++) {
          objArray[i].FirstName = "First Name: " + objArray[1].FirstName;
          console.log(objArray[i]);
        }
        return objArray;
      }
   }
 </script>

我想从状态中提取值,然后进行客户端javascript格式化以用于显示。当我尝试使用/引用/修改状态中的数据时,就像变量死掉一样,只是对其自身进行了未定义。我在这里缺少基本的Vue.js概念吗?任何帮助深表感谢。

vue.js
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.