三、Vue组件间传值
  1. 父组件传递给子组件(单向数据流)
    1. 父组件页面在引用子组件的地方写上属性值
    <template>
      <div class="home">
        <img alt="Vue logo" src="../assets/logo.png">
        <HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
      </div>
    </template>
    
    1. 子组件内进行接收
    @Options({
      props: {
        msg: {
          type: String
          default: ""
        }
      }
    })
    
  2. 子组件传递给父组件
    1. 子组件使用$emit绑定事件发送数据
    methods: {
        send() {
          this.$emit("send", 11, 22)
        }
      },
    }
    
    1. 父组件中对子组件添加事件属性
    <template>
      <div class="home">
        <img alt="Vue logo" src="../assets/logo.png">
        <HelloWorld msg="Welcome to Your Vue.js + TypeScript App" @send="deal_send"/>
      </div>
    </template>
    
    1. 父组件处理数据
    methods: {
        deal_send(a: any, b: any) {
    
        }
    }
    
posted on 2022-07-01 19:01  仓鼠不爱吃辣条  阅读(38)  评论(0)    收藏  举报

页尾

页尾

页尾

页尾

页尾

页尾

页尾