v2.5.2
Giriş yap

Vuejs v-model Optional Chaining

trsherlock
312 defa görüntülendi ve 1 kişi tarafından değerlendirildi
<input type="text" v-model="invoices?.[0]?.invoiceID">
<input type="text" v-model="invoices?.[0]?.date">
<input type="text" v-model="invoices?.[0]?.userID">

Herkese merhaba. Vue js ile Optional Chaining nasıl kullanabilirim?
Xml dosyalarından veri çekiyorum.
Dizi boş olduğu zaman inputlar da boş olsun.

trsherlock
504 gün önce

Neyse internette bir örnek gördüm iş görür gibi. Metod kullanarak çözmüş.

<div id="ebelge">
        <div class="h-[100vh] bg-gradient-to-b from-[#1fa2ff] to-[#12d8fa] to-[#a6ffcb]">
            <div>
                <input type="text" v-model="optianal('evrakNo')">
                <input type="text" v-model="optianal('aliciVKN')">
                <input type="file" multiple accept=".xml" @change="parseXML" />
            </div>
        </div>
    </div>
    <script>
        const newVue = new Vue({
            el: '#ebelge',
            data: {
                index: 0,
                invoices: [
                    {
                        evrakNo: "1"
                    }
                ]
            },
            methods: {
                optianal(e) {
                    switch (e) {
                        case "evrakNo":
                            return this.invoices?.[this.index]?.evrakNo
                            break;
                        case "aliciVKN":
                            return this.invoices?.[this.index]?.aliciVKN
                            break;
                        default:
                            break;
                    }
                },
                parseXML(e) {
                    this.invoices = [];
                    this.index = 0;
                    const $xmlFiles = e.target.files;
                    for (let i of $xmlFiles) {
                        $.get(
                            URL.createObjectURL(i),
                            (xml) => {
                                this.invoices.push($.fn.earsivXML(xml, i.name));
                            },
                            "xml"
                        );
                    }
                }
            }
        })

    </script>