欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue 動態(tài)生成數(shù)據(jù)字段的實例

 更新時間:2022年04月02日 17:24:12   作者:龍旗天下  
這篇文章主要介紹了Vue 動態(tài)生成數(shù)據(jù)字段的實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

動態(tài)生成數(shù)據(jù)字段實例

1.父組件定義data里面的數(shù)據(jù)字段

異步請求獲取數(shù)據(jù)(一種配置數(shù)據(jù),一種實際數(shù)據(jù))

data () {
? return {
? ? config: [],
? ? list: []
? };
}

2.子組件接收數(shù)據(jù)

props: {
? config: Array,
? list: Array
},
data () {
? return {
? ? newConfig: [],
? ? configLength: 0,
? ? newList: []
? };
}

3.因為獲取數(shù)據(jù)是異步操作

因此需要監(jiān)聽數(shù)據(jù)變化,當(dāng)有數(shù)據(jù)時展示子組件

configLoaded: false,
listLoaded: false

定義上面兩個變量來判斷數(shù)據(jù)是否加載完成,在異步獲取完數(shù)據(jù)后賦值為true,并監(jiān)聽

watch: {
? configLoaded (n, o) {
? ? ? ? this.configLoaded = n;
? },
? listLoaded (n, o) {
? ? this.listLoaded = n;
? }
},

4.計算屬性計算兩個變量是否均完成

并執(zhí)行v-if

computed: {
? showItem () {
? ? return this.configLoaded && this.listLoaded;
? }
},
<list-item :config="config" :list="list" v-if="showItem"></list-item>

5.子組件完整代碼

<template>
? <div>
? ? <div class="item iconfont border-bottom" v-for="(item,index) of newList" :key="index">
? ? ? <p v-for="(m,i) of item" :key="i">{{m.name}} {{m.text}}</p>
? ? </div>
? </div>
</template>
<script>
? export default {
? ? name: 'Item',
? ? props: {
? ? ? config: Array,
? ? ? list: Array
? ? },
? ? data () {
? ? ? return {
? ? ? ? newConfig: [],
? ? ? ? configLength: 0,
? ? ? ? newList: []
? ? ? };
? ? },
? ? mounted () {
? ? ? this.toConfig();
? ? },
? ? methods: {
? ? ? toConfig () {
? ? ? ? this.configLength = this.config.length;
? ? ? ? for (let i in this.config) {
? ? ? ? ? let configItem = this.config[i];
? ? ? ? ? this.newConfig.push({name: configItem.fieldName, text: configItem.fieldDesc});
? ? ? ? }
? ? ? ? for (let l in this.list) {
? ? ? ? ? let item = this.list[l];
? ? ? ? ? let childList = [];
? ? ? ? ? for (var c in this.newConfig) {
? ? ? ? ? ? let config = this.newConfig[c];
? ? ? ? ? ? for (let key in item) {
? ? ? ? ? ? ? if (config.name === key) {
? ? ? ? ? ? ? ? childList.push({name: config.text, text: item[key]});
? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? }
? ? ? ? ? this.newList.push(childList);
? ? ? ? }
? ? ? }
? ? }
? };
</script>
?
<style lang="stylus" ref="stylesheet/stylus">
</style>

表單動態(tài)生成字段  

checkbox 多選,沒有默認(rèn)值的時候,一定要給一個空數(shù)組,不然就展示不出來

<el-form ref="myForm" :model="form" :rules="rules" :disabled="disabledBoolean">
 <el-row>
<el-col>
  <div v-for="(item ,index) in extendFieldColumns" :key="index" >
    <el-col v-if="item.type === 'input'" :span="defaultSpan">
      <el-form-item  :label-width="defaultLabelWidth" size="small" :rules="extendFieldRules[item.prop]" :prop="'extendField.'+item.prop" :label="item.label+':'" >
        <el-input  v-model="form.extendField[item.prop]" :maxlength="item.maxlength" placeholder="請輸入內(nèi)容"></el-input>
      </el-form-item>
    </el-col>
    <el-col v-if="item.type === 'radio'"  :span="defaultSpan">
      <el-form-item  :label-width="defaultLabelWidth" size="small" :rules="extendFieldRules[item.prop]" :prop="'extendField.'+item.prop" :label="item.label+':'"  >
        <el-radio-group v-model="form.extendField[item.prop]" >
          <el-radio v-for="(option,index1) in item.dicData"  :key="index1" :label="option.label"  >{{option.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-col>
    <el-col v-if="item.type === 'select'" :span="defaultSpan" >
      <el-form-item  :label-width="defaultLabelWidth" size="small" :prop="'extendField.'+item.prop"  :label="item.label+':'"  :rules="extendFieldRules[item.prop]">
        <el-select  v-model="form.extendField[item.prop]"  placeholder="請選擇">
          <el-option
v-for="(option,index2) in item.dicData"
:key="index2"
:label="option.label"
:value="option.label">
          </el-option>
        </el-select>
      </el-form-item>
    </el-col>
    <el-col v-if="item.type === 'checkbox'" :span="defaultSpan" >
      <el-form-item  :label-width="defaultLabelWidth" size="small" :prop="'extendField.'+item.prop"  :label="item.label+':'" :rules="extendFieldRules[item.prop]">
        <el-checkbox-group v-model="form.extendField[item.prop]"  >
          <el-checkbox v-for="city in item.dicData"  :label="city.label" :key="city.label">{{city.label}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-col>
    <el-col v-if="item.type === 'number'" :span="defaultSpan" >
      <el-form-item  :label-width="defaultLabelWidth" size="small" :prop="'extendField.'+item.prop" :label="item.label+':'" :rules="extendFieldRules[item.prop]">
        <el-input-number v-model="form.extendField[item.prop]"  :max="item.maxlength"  ></el-input-number>
      </el-form-item>
    </el-col>
    <el-col v-if="item.type === 'textarea'" :span="defaultSpan" >
      <el-form-item  :label-width="defaultLabelWidth" size="small" :prop="'extendField.'+item.prop" :label="item.label+':'" :rules="extendFieldRules[item.prop]">
        <el-input
          v-model="form.extendField[item.prop]"
          :maxlength="item.maxlength"
          type="textarea"
          placeholder="請輸入內(nèi)容"
        >
        </el-input>
      </el-form-item>
    </el-col>
    <el-col v-if="item.type === 'date'" :span="defaultSpan" >
      <el-form-item  :label-width="defaultLabelWidth" size="small" :prop="'extendField.'+item.prop" :label="item.label+':'" :rules="extendFieldRules[item.prop]">
        <el-date-picker
          v-model="form.extendField[item.prop]"
          type="date"
          placeholder="選擇日期">
        </el-date-picker>
      </el-form-item>
    </el-col>
  </div>
</el-col>
</el-row>
</el-form>

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。 

相關(guān)文章

  • 微信小程序開發(fā)實現(xiàn)消息框彈出

    微信小程序開發(fā)實現(xiàn)消息框彈出

    在小程序的wxml文件中創(chuàng)建消息框,消息框一般包含要提示的消息內(nèi)容以及確認(rèn)和取消按鈕,在小程序的wxss文件中定義消息框的樣式,在小程序的js文件中,我們需要通過Animation對象實現(xiàn)消息框的彈出動畫
    2023-12-12
  • Vue3+Vite項目引入Bootstrap5、bootstrap-icons方式

    Vue3+Vite項目引入Bootstrap5、bootstrap-icons方式

    這篇文章主要介紹了Vue3+Vite項目引入Bootstrap5、bootstrap-icons方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue之computed的緩存特性

    vue之computed的緩存特性

    這篇文章主要介紹了vue之computed的緩存特性,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Vue2實現(xiàn)全局水印效果的示例代碼

    Vue2實現(xiàn)全局水印效果的示例代碼

    這篇文章主要為大家學(xué)習(xí)介紹了如何利用Vue2實現(xiàn)全局水印的效果,文中的示例代碼簡潔易懂,具有一定的借鑒價值,感興趣的小伙伴可以了解下
    2023-07-07
  • 解決element UI 自定義傳參的問題

    解決element UI 自定義傳參的問題

    今天小編就為大家分享一篇解決element UI 自定義傳參的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • vue+element-ui表格封裝tag標(biāo)簽使用插槽

    vue+element-ui表格封裝tag標(biāo)簽使用插槽

    這篇文章主要介紹了vue+element-ui表格封裝tag標(biāo)簽使用插槽,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • Vue組件高級通訊之$attrs與$listeners

    Vue組件高級通訊之$attrs與$listeners

    這篇文章主要為大家介紹了Vue組件高級通訊之$attrs與$listeners使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • Vue.js每天必學(xué)之過渡與動畫

    Vue.js每天必學(xué)之過渡與動畫

    Vue.js每天必學(xué)之過渡與動畫,對Vue.js過渡與動畫進行深入學(xué)習(xí),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • vue項目打包后上傳至GitHub并實現(xiàn)github-pages的預(yù)覽

    vue項目打包后上傳至GitHub并實現(xiàn)github-pages的預(yù)覽

    這篇文章主要介紹了vue項目打包后上傳至GitHub并實現(xiàn)github-pages的預(yù)覽,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • Vue路由傳遞query參數(shù)兩種方式

    Vue路由傳遞query參數(shù)兩種方式

    路由是可以傳遞參數(shù)的,一般使用query進行傳參,有兩種方式,本溫酒通過代碼示例給大家介紹這兩種傳遞方式,感興趣的小伙伴可以參考閱讀
    2023-06-06

最新評論