简体   繁体   English

Vue从父组件绑定子组件数据

[英]Vue bind child component data from parent

I need to bind my child component data ( inputData ) from parent component but it's not working i cannot find where is my mistake我需要从父组件绑定我的子组件数据( inputData )但它不起作用我找不到我的错误在哪里

app.js应用程序.js

let vm = new Vue({
    el: "#app",
    components: {
        'modal-panel': modal,
        'rich-select': richSelect,
        'file-upload': uploader,
    },
    data(){ return {
        isModalActive: false,
        inputData: null
    }} ,
    methods: {
        toggleModal(){
            this.isModalActive = !this.isModalActive
        },
        modalData(){
            this.inputData = 'Example Data'
        }
    }
});

Modal.vue模态的.vue

<template>
  <input type="text" :value="inputData" >
</template>



export default {
    name: 'modal',
    props: ['inputData'],
    mounted(){
        console.log('modal Mounted')
    }
};

inside my blade i'am calling modal component like this在我的刀片内部,我正在调用这样的模态组件

<div class="container"  id="app">    
  <modal-panel v-if="isModalActive" @close="toggleModal" :inputData="inputData"></modal-panel>
</div>

when i test that code all methods are working but inside Modal.vue input still not binding当我测试该代码时,所有方法都在工作,但在Modal.vue 中input仍然没有绑定

You've to use the prop with kebab-case format as follows:您必须使用 kebab-case 格式的道具,如下所示:

<modal-panel v-if="isModalActive" @close="toggleModal" :input-data="inputData"></modal-panel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM