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

詳解vue中父子組件傳遞參數(shù)props的實(shí)現(xiàn)方式

 更新時間:2023年07月30日 09:42:16   作者:tommoq  
這篇文章主要給大家介紹了在vue中,父子組件傳遞參數(shù)?props?實(shí)現(xiàn)方式,文章通過代碼示例介紹的非常詳細(xì),對我們的學(xué)習(xí)或工作有一定的參考價值,需要的朋友可以參考下

通過 Prop 向子組件傳遞數(shù)據(jù)

001:父組件=====》子組件通信

<template>
    <div>
       <h1>這里是父元素</h1>
       //******
       <childComponent :detailMes="detailMes"/>
    </div>
</template>
<script>
    import childComponent from  './childComponent'
    export default {
        name:"parentComponent",
        data() {
            return {
                detailMes:'111'
            }
        },
        components: {
            childComponent,
        },
    }
</script>

子組件

<template>
  <div>
    數(shù)據(jù)需要從父元素傳遞過來哦:{{detailMes}}
  </div>
</template>
<script>
  export default {
    name:'childComponent',
    data() {
      return {
      }
    },
    props: {
      detailMes:{
        type : String,
      }
    },
    methods: {
      name() {
      }
    }
  }

002:子組件=====》父組件通信

(要求父組件先給子組件一個函數(shù))
列表數(shù)據(jù)在父組件,循環(huán)的ul>li在子組件,現(xiàn)在在組件刪除數(shù)據(jù),需要通知父組件

<template>
    <div>
       <h1>這里是父</h1>
       //父組件先給子組件一個函數(shù)
       <childComponent :list="list" :del="del"/>
    </div>
</template>
<script>
    import childComponent from  './childComponent'
    export default {
        data() {
            return {
                list:[
                    {id:"001",stuName:'學(xué)生a'},
                    {id:"002",stuName:'學(xué)生b'},
                ]
            }
        },
        components: {
            childComponent,
        },
        methods: {
            del(id) {
                const idx=this.list.findIndex(v=>v.id==id);
                if(idx>-1){
                    this.list.splice(idx,1)
                }
                // this.list=this.list.filter(item=>item.id!==id)
            }
        },
    }
</script>
<template>
  <div>
    子組件
    <ul>
      <li v-for="item of list" :key="item.id">
        <span>{{item.stuName}}</span>
        <button @click="dele(item.id)" class="red">x</button>
      </li>
    </ul>
  </div>
</template>
<script>
  export default {
    name:'childComponent',
    data() {
      return {
      }
    },
    props: {
      // 父元素傳遞過來的方法
      list:{},
      // 父組件傳遞過來的方法
      del:{}
    },
    methods: {
      dele(ids) {
        // 通知父元素,快刪除數(shù)據(jù)了
        // 去調(diào)用父組件的方法
        this.del(ids);
      }
    }
  }

003 傳遞 多層傳遞下去

<template>
    <div>
       <h1>這里是父</h1>
       <childComponent :msg="msg"/>
    </div>
</template>
<script>
    import childComponent from  './childComponent'
    export default {
        data() {
            return {
                msg:'這條數(shù)據(jù)需要通過層層傳遞下去'
            }
        },
        components: {
            childComponent,
        },
    }
</script>
<template>
  <div>
    子組件
    <grandsonComponent :msg="msg"></grandsonComponent>
  </div>
</template>
<script>
import grandsonComponent from '@/components/grandsonComponent.vue';
  export default {
    components: {
      grandsonComponent,
    },
    props: {
      msg:{}
    },
  }
</script>
<template>
    <div>
       這是統(tǒng)計(jì)的{{msg}}的數(shù)據(jù)
    </div>
</template>
<script>
    export default {
        name:'grandsonComponent',
        props: {
            msg: {}
        },
    }
</script>

到此這篇關(guān)于詳解vue中父子組件傳遞參數(shù)props實(shí)現(xiàn)方式的文章就介紹到這了,更多相關(guān)vue父子組件傳遞props內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 淺談Vue數(shù)據(jù)響應(yīng)思路之?dāng)?shù)組

    淺談Vue數(shù)據(jù)響應(yīng)思路之?dāng)?shù)組

    這篇文章主要介紹了淺談Vue數(shù)據(jù)響應(yīng)思路之?dāng)?shù)組,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • Vue和React組件之間的傳值方式詳解

    Vue和React組件之間的傳值方式詳解

    這篇文章主要介紹了Vue和React組件之間的傳值方式詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • vxe-table如何在單元格中渲染簡單的餅圖

    vxe-table如何在單元格中渲染簡單的餅圖

    這篇文章主要介紹了vxe-table如何在單元格中渲染簡單的餅圖,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue.js添加組件操作示例

    Vue.js添加組件操作示例

    這篇文章主要介紹了Vue.js添加組件操作,結(jié)合實(shí)例形式分析了vue.js組件的注冊、調(diào)用相關(guān)操作技巧,需要的朋友可以參考下
    2018-06-06
  • vue + vuex todolist的實(shí)現(xiàn)示例代碼

    vue + vuex todolist的實(shí)現(xiàn)示例代碼

    這篇文章主要介紹了vue + vuex todolist的實(shí)現(xiàn)示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • 詳解element-ui設(shè)置下拉選擇切換必填和非必填

    詳解element-ui設(shè)置下拉選擇切換必填和非必填

    這篇文章主要介紹了詳解element-ui設(shè)置下拉選擇切換必填和非必填,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • vue中keep-alive組件使用和一些基礎(chǔ)配置方法

    vue中keep-alive組件使用和一些基礎(chǔ)配置方法

    本文主要介紹了Vue中keep-alive組件的使用方法和一些基礎(chǔ)配置,keep-alive是Vue中的一個抽象組件,可以緩存組件實(shí)例,提高性能,本文給大家介紹vue中keep-alive組件使用和一些基礎(chǔ)配置方法,感興趣的朋友一起看看吧
    2024-10-10
  • 關(guān)于vue-router的使用及實(shí)現(xiàn)原理

    關(guān)于vue-router的使用及實(shí)現(xiàn)原理

    這篇文章主要介紹了關(guān)于vue-router的使用及實(shí)現(xiàn)原理,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • vue如何使用外部特殊字體的操作

    vue如何使用外部特殊字體的操作

    這篇文章主要介紹了vue如何使用外部特殊字體的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue實(shí)現(xiàn)頭像上傳功能

    vue實(shí)現(xiàn)頭像上傳功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)頭像上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07

最新評論