鍍金池/ 問(wèn)答/HTML/ vue項(xiàng)目data functions should return an obj

vue項(xiàng)目data functions should return an object

問(wèn)題描述

在vue項(xiàng)目中提示錯(cuò)誤,data functions should return an object

clipboard.png

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

<template>
    <el-dialog title="Login" :visible.sync="dialogFormVisible" :modal="true" :modal-append-to-body="false" class="my-dialog">
        <el-form :model="form" label-width="100px" :rules="rules" ref="form">
            <el-form-item label="Username" prop="username">
                <el-input v-model="form.username" auto-complete="off" prefix-icon="iconfont icon-user"></el-input>
            </el-form-item>
            <el-form-item label="Password" prop="password">
                <el-input type="password" @keyup.enter.native="loginMethod" v-model="form.password" auto-complete="off" prefix-icon="iconfont icon-password"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">Cancel</el-button>
            <el-button type="primary" @click.native="loginMethod">Log in</el-button>
        </div>
    </el-dialog>
</template>
export default {
  data() {
    return {
      dialogFormVisible: false,
      form: {
        username: "",
        password: ""
      },
      rules: {
        username: [
          {
            required: true,
            message: "please input your username",
            tigger: "blur"
          }
        ],
        password: [
          {
            required: true,
            message: "please input your password",
            tigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    loginMethod() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$store
            .dispatch("LoginByUsername", this.form)
            .then(() => {
              Message.success("Login Success");
              this.$router.push({ path: '/' });
            })
            .catch(err => {
              Message.info(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};```

### 你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?
回答
編輯回答
奧特蛋

終于找到了,是在Message.info(err)錯(cuò)了,Message.info()是element-ui的組件,只能接受字符串,不能接受對(duì)象。
改為Message.info(err.message)就好了。

2018年8月4日 16:43