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

vue components 動態(tài)組件詳解

 更新時間:2021年11月10日 10:14:26   作者:taoqidejingling  
這篇文章主要介紹了vue components 動態(tài)組件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

數(shù)組發(fā)生變化時,動態(tài)加載相應(yīng)數(shù)據(jù)

場景:點擊不同組件名稱,界面顯示相應(yīng)組件

步驟一:導(dǎo)入所需組件

步驟二:點擊 tab 選項卡,將對應(yīng)組件名添加進(jìn)數(shù)組

步驟三:使用動態(tài)組件,:is 屬性綁定組件名

<div v-for="(item, index) in componentData" :key="index">
  <components :is="item.componentName"/>
</div>

案例:監(jiān)聽對象中屬性變化,深度監(jiān)聽

<!-- DynamicComponent.vue -->
<template>
  <section>
    <div v-for="(item, index) in componentData" :key="index">
      <components :is='item.componentName' :params="item.content" />
    </div>
  </section>
</template>
<script>
import PageOne from './pageComponents/PageOne'
import PageTwo from './pageComponents/PageTwo'
import PageThree from './pageComponents/PageThree'
export default{
  name: 'DynamicComponent',
  components: {
    PageOne,
    PageTwo,
    PageThree
  },
  data () {
    return {
      componentData: [
        {
          componentName: 'PageOne',
          content: {
            title: '標(biāo)題一'
          }
        },
        {
          componentName: 'PageTwo',
          content: {
            title: '標(biāo)題二'
          }
        }
      ]
    }
  }
}
</script>
<!-- PageOne -->
<template>
  <section>
    {{content}}
  </section>
</template>
<script>
export default{
  name: 'PageOne',
  props: {
    params: {
      type: Object,
      default: function(){
        return {}
      }
    }
  },
  data () {
    return {
      content: this.params.title
    }
  },
  watch: {
    params: {
      handler(newVal, oldVal){
        this.content = newVal.title
      },
      deep: true,
      immediate: true
    }
  }
}
</script>
<!-- PageTwo -->
<template>
  <section>
    {{content}}
  </section>
</template>
<script>
export default{
  name: 'PageTwo',
  props: {
    params: {
      type: Object,
      default: function(){
        return {}
      }
    }
  },
  data () {
    return {
      content: this.params.title
    }
  },
  watch: {
    params: {
      handler(newVal, oldVal){
        this.content = newVal.title
      },
      deep: true,
      immediate: true
    }
  }
}
</script>

總結(jié)

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!

數(shù)組發(fā)生變化時,動態(tài)加載相應(yīng)數(shù)據(jù)

場景:點擊不同組件名稱,界面顯示相應(yīng)組件

步驟一:導(dǎo)入所需組件

步驟二:點擊 tab 選項卡,將對應(yīng)組件名添加進(jìn)數(shù)組

步驟三:使用動態(tài)組件,:is 屬性綁定組件名

<div v-for="(item, index) in componentData" :key="index">
  <components :is="item.componentName"/>
</div>

案例:監(jiān)聽對象中屬性變化,深度監(jiān)聽

<!-- DynamicComponent.vue -->
<template>
  <section>
    <div v-for="(item, index) in componentData" :key="index">
      <components :is='item.componentName' :params="item.content" />
    </div>
  </section>
</template>
<script>
import PageOne from './pageComponents/PageOne'
import PageTwo from './pageComponents/PageTwo'
import PageThree from './pageComponents/PageThree'
export default{
  name: 'DynamicComponent',
  components: {
    PageOne,
    PageTwo,
    PageThree
  },
  data () {
    return {
      componentData: [
        {
          componentName: 'PageOne',
          content: {
            title: '標(biāo)題一'
          }
        },
        {
          componentName: 'PageTwo',
          content: {
            title: '標(biāo)題二'
          }
        }
      ]
    }
  }
}
</script>
<!-- PageOne -->
<template>
  <section>
    {{content}}
  </section>
</template>
<script>
export default{
  name: 'PageOne',
  props: {
    params: {
      type: Object,
      default: function(){
        return {}
      }
    }
  },
  data () {
    return {
      content: this.params.title
    }
  },
  watch: {
    params: {
      handler(newVal, oldVal){
        this.content = newVal.title
      },
      deep: true,
      immediate: true
    }
  }
}
</script>
<!-- PageTwo -->
<template>
  <section>
    {{content}}
  </section>
</template>
<script>
export default{
  name: 'PageTwo',
  props: {
    params: {
      type: Object,
      default: function(){
        return {}
      }
    }
  },
  data () {
    return {
      content: this.params.title
    }
  },
  watch: {
    params: {
      handler(newVal, oldVal){
        this.content = newVal.title
      },
      deep: true,
      immediate: true
    }
  }
}
</script>

總結(jié)

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!

相關(guān)文章

  • vue項目中input輸入框輸入不了值問題及解決

    vue項目中input輸入框輸入不了值問題及解決

    這篇文章主要介紹了vue項目中input輸入框輸入不了值問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Element-Plus?el-col、el-row快速布局及使用方法

    Element-Plus?el-col、el-row快速布局及使用方法

    這篇文章主要介紹了Element-Plus?el-col、el-row快速布局及使用方法,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-12-12
  • vue之監(jiān)聽器的使用案例詳解

    vue之監(jiān)聽器的使用案例詳解

    這篇文章主要介紹了vue之監(jiān)聽器的使用案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • Vue項目如何改變屏幕尺寸重新刷新頁面-計算頁面尺寸

    Vue項目如何改變屏幕尺寸重新刷新頁面-計算頁面尺寸

    這篇文章主要介紹了Vue項目如何改變屏幕尺寸重新刷新頁面-計算頁面尺寸,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 一文了解Vue中的nextTick

    一文了解Vue中的nextTick

    Vue中的 nextTick 涉及到Vue中DOM的異步更新,感覺很有意思,特意了解了一下。其中關(guān)于 nextTick 的源碼涉及到不少知識,很多不太理解,暫且根據(jù)自己的一些感悟介紹下 nextTick
    2019-05-05
  • vue.js實現(xiàn)表格合并示例代碼

    vue.js實現(xiàn)表格合并示例代碼

    最近工作中遇到一個需求,是要做一個頁面放張大表格用來顯示數(shù)據(jù)項,純粹為了view層操作方便,就用了vue做渲染。然而又被提出了一個需求,需要相鄰的相同值的行數(shù)據(jù)項進(jìn)行單元格合并,這就醉了。沒辦法,只能想辦法解決,下面通過這篇文章來一起看看吧。
    2016-11-11
  • vue之moment的使用方式

    vue之moment的使用方式

    這篇文章主要介紹了vue之moment的使用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • vue項目前端微信JSAPI與外部H5支付相關(guān)實現(xiàn)過程及常見問題

    vue項目前端微信JSAPI與外部H5支付相關(guān)實現(xiàn)過程及常見問題

    這篇文章主要介紹了vue項目前端微信JSAPI與外部H5支付相關(guān)實現(xiàn)過程及常見問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • vue移動端微信授權(quán)登錄插件封裝的實例

    vue移動端微信授權(quán)登錄插件封裝的實例

    今天小編就為大家分享一篇vue移動端微信授權(quán)登錄插件封裝的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 一篇文章帶你搞懂Vue虛擬Dom與diff算法

    一篇文章帶你搞懂Vue虛擬Dom與diff算法

    這篇文章主要給大家介紹了關(guān)于Vue虛擬Dom與diff算法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08

最新評論