Laravel Vue,提交后从组件中传递数据

cetgtptt  于 2023-01-21  发布在  Vue.js
关注(0)|答案(1)|浏览(110)

我需要一些关于如何从窗体中的组件获取值的帮助。
这是表格也是照片:form

<form @submit.prevent="form.patch(route('profile.update.account'))" class="mt-6 space-y-6">
            <div>
                <InputLabel for="adresa" value="Adresa" />

                <TextInput
                    id="adresa"
                    type="text"
                    class="mt-1 block w-full"
                    v-model="form.adresa"
                    required
                    autofocus
                    autocomplete="adresa"
                />

                <InputError class="mt-2" :message="form.errors.adresa" />
            </div>

            <DropdownCountries 
                id="tara"
                v-model="form.tara"
                required
                autocomplete="Romania"
            />

            <div class="flex items-center gap-4">
                <PrimaryButton :disabled="form.processing">Save</PrimaryButton>

                <Transition enter-from-class="opacity-0" leave-to-class="opacity-0" class="transition ease-in-out">
                    <p v-if="form.recentlySuccessful" class="text-sm text-gray-600">Saved.</p>
                </Transition>
            </div>
        </form>

'
有组件也是一张照片:dropdown
'

<template>
    <div class="container">
        <div class="row justify-content-center" style="margin: 20px 0px 20px 0px;">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-body">
                        <div class="form-group">
                            <select name="tara" class='form-control' v-model='country' @change='getStates()'>
                                <option value='0' >Select Country</option>
                                <option v-for='data in countries' :value='data.id'>{{ data.name }}</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <select name="judet" class='form-control' v-model='state' @change='getCities()'>
                                <option value='0' >Select State</option>
                                <option v-for='data in states' :value='data.id'>{{ data.name }}</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <select name="oras" class='form-control' v-model='city'>
                                <option value='0' >Select City</option>
                                <option v-for='data in cities' :value='data.id'>{{ data.name }}</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            country: 180,
            countries: [],
            state: 0,
            states: [],
            city: 0,
            cities: [],
        }
    },
    methods:{
        getCountries: function(){
            axios.get('/api/tari')
                .then(function (response) {
                    this.countries = response.data;
                }.bind(this));
        },
        getStates: function() {
            axios.get('/api/judete/' + this.country).then(function(response){
                this.states = response.data;
            }.bind(this));
        },
        getCities: function() {
            axios.get('/api/orase/' + this.state).then(function(response) {
                this.cities = response.data
            }.bind(this));
        }
    },
    created: function(){
        this.getCountries()
    }
}

</script>

'
我的问题是,当我按保存按钮提交表单的下拉列表中的值不适用:response
我已经在网上找了2个小时了,有人能解释一下为什么吗?

h5qlskok

h5qlskok1#

您应该检查以下内容:**v-model and child components?**这应该可以回答您的问题。如果您需要有关如何传递v模型值的更多信息,请告诉我。

相关问题