Skip to content

Vue 创建组件与父子组件之间的交互

yangbo edited this page May 20, 2017 · 2 revisions

创建一个子组件Child

<template>
    <span>{{ message }}</span>
</template>

<script>
    export default {
        name: 'child',
        props: {
            message: String
        }
    }
</script>

在父组件中使用

<template>
    <div class="hello">
        <Child message="Hello child!" />
    </div>

</template>

<script>
    import Child from './Child'

    const data = {

    }
    export default {
        name: 'hello',
        components: { Child },
        data () {
            return data
        }
    }
</script>