使用-Prop-传递数据(父组件通过 props 向下传递数据给子组件)

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用-Prop-传递数据title>
    <script src="vue.js">script>
head>
<body>
<div id="app">
    
    <child my-message="hello!">child>

    
    <child2 v-bind:cm="parentMsg">child2>
div>
<script>
    Vue.component('child', {
        props    : ['myMessage'],
        template : '{{ myMessage }}'
    })


    Vue.component('child2', {
        props    : ['cm'],
        template : '{{ cm }}'
    })

    new Vue({
        el         : '#app',
        data : {
            parentMsg : 'parentMsg'
        }        
    })

script>
body>
html>

 

转载于:https://www.cnblogs.com/adaBlog/p/7117070.html

你可能感兴趣的:(使用-Prop-传递数据(父组件通过 props 向下传递数据给子组件))