Vue项目实战01: vue里父传子 传事件(easy)
生活随笔
收集整理的這篇文章主要介紹了
Vue项目实战01: vue里父传子 传事件(easy)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
vue中的組件通信 相信小伙伴們已經達到爐火純青的地步了
提到vue里父子組件通信 腦子里第一個想到的是不是使用$emit來傳遞.
實現肯定是能實現的 下面我們一起看一下一種簡單的方法
父組件:
在父組件中定義了 傳遞的方法 method 并在父組件中打印
<template><div class="about"><Son :arr="arr"></Son></div> </template> <script> import Son from './About' export default {components:{Son},data(){return{arr:[{id: 1,name: '叮咚',method: () => {console.log('叮咚')}},{id: 2,name: '小小',method: () => {console.log('小小')}}]}} } </script>子組件
<template><div class="about"><div v-for="(item, index) in arr" :key="index"><button @click="item.method()">{{ item.name }}</button></div></div> </template> <script> export default {props: {arr: {type: Array,default: () => [],},}, }; </script>總結
以上是生活随笔為你收集整理的Vue项目实战01: vue里父传子 传事件(easy)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VirMach VPS安装宝塔面板教程
- 下一篇: 三星电子Q2营收472亿美元,净利13.