Vue将数据从组件传递到另一个组件

时间:2020-09-28 20:27:49

标签: vue.js axios vuex

我正在为用户创建“创建帐户”流程,但是我无法将数据从一个组件传递到另一个组件。第一个组件具有带“承租人”,“房东”,“承包商”选项的单选按钮。一旦用户选择了“承租人”,数据就应该传递到下一步,他们将在表单中填写姓名和所有好东西。提交后,它们都应该一起送到后端。

acc-for.vue,下面带有单选按钮组件。

<template>
  <div>
    <v-app
      style="background-image: url('https://blog.modsy.com/wp-content/uploads/2019/06/D2_Full.jpg')"
    >
      <v-container class="pa-12">
        <v-row>
          <v-card class="pa-16">
            <v-card-title>
              Are you a?
            </v-card-title>
            <v-radio-group v-model="selectedValue" @change="selectedAcc">
              <v-radio
                v-for="account in accountType"
                :key="account.name"
                :value="account.name"
                :label="account.name"
              ></v-radio>
            </v-radio-group>
            <v-row>
              <v-btn rounded color="black" class="white--text" href="/login"
                >Back</v-btn
              >
              <v-btn
                rounded
                color="black"
                class="white--text"
                @click="selected(accountSelected)"
                >Next</v-btn
              >
              <!-- href="/create-acc" -->
            </v-row>
          </v-card>
        </v-row>
      </v-container>
    </v-app>
  </div>
</template>
<script>
import { mapMutations } from "vuex";

export default {
  data() {
    return {
      selectedValue: false,
    };
  },
  computed: {
    accountType() {
      return this.$store.state.accountType;
    },
    selected() {
      return this.$store.state.selectedAccType;
    },
  },
  methods: {
    ...mapMutations(["SELECTED_ACCOUNT_TYPE"]),

    selectedAcc(e) {
      this.$emit("selected-accountType", e);
    },
  },
};
</script>
<style></style>

createAccount.vue此组件具有fNamelName以及所有这些好东西的形式。

<template>
  <div>
    <v-app
      style="background-image: url('https://blog.modsy.com/wp-content/uploads/2019/06/D2_Full.jpg')"
    >
      <v-container class="pa-12">
        <v-row>
          <v-card class="pa-16">
            <v-card-title>
              {{ selectedTypeUser }}
            </v-card-title>
            <v-form>
              <v-text-field
                class="pa-4"
                type="text"
                v-model="newUser_fName"
                label="First Name"
              />
              <v-text-field
                class="pa-4"
                type="text"
                v-model="newUser_lName"
                label="Last Name"
              />
              <v-text-field
                class="pa-4"
                type="text"
                v-model="newUser_email"
                label="Email"
              />
              <v-text-field
                class="pa-4"
                type="text"
                v-model="newUser_password"
                label="Password"
              />
              <v-row>
                <v-btn rounded color="black" class="white--text" href="/acc-for"
                  >Back</v-btn
                >
                <v-btn
                  @click="registerUser"
                  rounded
                  color="black"
                  class="white--text"
                  >Next</v-btn
                >
              </v-row>
            </v-form>
          </v-card>
        </v-row>
      </v-container>
    </v-app>
  </div>
</template>
<script>
import { mapMutations } from "vuex";
import axios from "axios";
export default {
  data() {
    return {
      newUser_fName: "",
      newUser_lName: "",
      newUser_email: "",
      newUser_password: "",
    };
  },

  methods: {
    ...mapMutations(["ADD_USER"]),
    registerUser() {
      let config = {
        headers: {
          "Content-Type": "application/json",
        },
      };
      axios
        .post(
          "http://localhost:7876/createUser",
          {
            fName: this.newUser_fName,
            lName: this.newUser_lName,
            email: this.newUser_email,
            password: this.newUser_email,
          },
          config
        )
        .then((response) => {
          console.log(response.statusText);
        })
        .catch((e) => {
          console.log("Error: ", e.response.data);
        });
    },
  },
};
</script>

store.js(状态)在下面

// import vue from "vue";
import vuex from "vuex";
import axios from "axios";
import Vue from "vue";

Vue.use(vuex, axios);

export default new vuex.Store({
    state: {
        users: [],
        accountType: [
            { name: "Tenant" },
            { name: "Landlord" },
            { name: "Contractor" }
        ],
        selectedAccType: [],
    },
    mutations: {
        ADD_USER: (state, payload) => {
            state.users.push(payload.user);
        },
        SELECTED_ACCOUNT_TYPE: (state, payload) => {
            state.selectedAccType.push(payload)
        }
    },
    actions: {
        addUser: ({ commit }, payload) => {
            commit("ADD_USER", payload);
        },
        selectAcc: ({ commit }, payload) => {
            commit("SELECTED_ACCOUNT_TYPE", payload)
        }
    },
    // getters: {
    //     addAccountType(state, e) {
    //         state.accountType.push(e)
    //     },
    // },
});

1 个答案:

答案 0 :(得分:0)

我在按钮上看到了这个

    With Chart1
        .Series.Clear()
        .Series.Add("Series1")
    End With

    Dim con As SqlConnection = New SqlConnection(MYCON)
    con.Open()
    Dim dadapter As SqlDataAdapter = New SqlDataAdapter("with union_cte as (
    select [DESC], 1 sort_order,
       SUM(case when [status]='ACTIVE' THEN 1 ELSE 0 END) [Active],
       SUM(case when [status]='INACTIVE ' THEN 1 ELSE 0 END) [INACTIVE],
       count(*) [TOTAL]
    from [master] 
    group by [DESC]
    union all 
    select 'TOTAL', 2 sort_order,
       SUM(case when [status]='ACTIVE' THEN 1 ELSE 0 END) [Active],
       SUM(case when [status]='INACTIVE ' THEN 1 ELSE 0 END) [INACTIVE],
       count(*) [TOTAL]
    from [master])
select *
from union_cte
order by sort_order, [DESC];", con)
    dadapter.Fill(dset, "DESC")
    Chart1.DataSource = dset.Tables("DESC")
    Dim series1 As Series = Chart1.Series("Series1")
    series1.ChartType = SeriesChartType.Column
    series1.Name = "ACTIVE"

    With Chart1
        .Series(0)("ColumnLabelStyle") = "Outside"
        .Series(0).BorderWidth = 1
        .Series(0).BorderColor = System.Drawing.Color.FromArgb(0, 0, 0)
        .ChartAreas(0).Area3DStyle.Enable3D = True
        .Series(series1.Name).XValueMember = "DESC"
        .Series(series1.Name).YValueMembers = "ACTIVE"
        .Series(0).LabelFormat = "{#,##0}"
        .Series(0).IsValueShownAsLabel = True        
        .Titles.Add("DESC")
    End With

但是我在您所附的代码中找不到具有该名称的方法。仔细检查您的姓名是否全部匹配,以及您是否在click事件上调用了正确的函数。