第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Vue - 在這種情況下如何傳遞數(shù)組?

Vue - 在這種情況下如何傳遞數(shù)組?

慕勒3428872 2023-04-20 17:01:20
這是我的示例代碼。我想創(chuàng)建一個(gè)小型表單生成器。我會(huì)有很多選擇字段。如何將數(shù)組傳遞到循環(huán)中?我的代碼不起作用,但我希望你知道我想要得到什么效果。<template>    <div>        <div v-for="(input, index) in formBuilder" :key="index">            <h1>{{ input.name }}</h1>            <div>                Options:<br />                {{ formBuilder.options }}            </div>        </div>    </div></template><script>import { mapState } from "vuex";export default {    data() {        return {            formBuilder: [                {                    name: "Name",                    options: this.versions,                },                {                    name: "Host",                    options: this.countryList,                },            ],        };    },    computed: mapState(["versions", "countryList"]),};</script>編輯。下面,我添加了一個(gè)有效的版本。但它能以更好的方式完成嗎?這是正確的方法嗎?有用:<template>    <div>        <div v-for="(input, index) in formBuilder" :key="index">            <h1>{{ input.name }}</h1>            <div>                Options:<br />                {{ input.options }}            </div>        </div>    </div></template><script>import { mapState } from "vuex";export default {    data() {        return {            formBuilder: [                {                    name: "Name",                    options: [],                },                {                    name: "Host",                    options: [],                },            ],        };    },    created() {        this.formBuilder[0].options = this.versions;        this.formBuilder[1].options = this.countryList;    },    computed: mapState(["versions", "countryList"]),};</script>
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

計(jì)算屬性是您的“正確解決方案”。

computed: {

? ...mapState(['versions', 'countryList']),

? formBuilder() {

? ? return [

? ? ? { name: "Name", options: this.versions },

? ? ? { name: "Host", options: this.countryList },

? ? ]

? }

}

解釋:

  • 如果您將代碼放入其中,created它只會(huì)formBuilder在組件創(chuàng)建時(shí)準(zhǔn)備一次。

  • 如果您使用,每次都會(huì)重新計(jì)算computed或更新。formBuilderthis.versionsthis.coutryList


查看完整回答
反對(duì) 回復(fù) 2023-04-20
  • 1 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)