01.vue组件-父组件向子组件传值

父组件向子组件传值

1. 效果

01.vue组件-父组件向子组件传值_第1张图片

 

2. 代码

DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>
    <script src="../table/js/vue.js">script>
head>

<body>
    <div id="app">
        <a href="#" @click.prevent="msg='登陸'">登陆a>
        <a href="#" @click.prevent="msg='注冊'">注册a>
        <login v-bind:parentmsg="msg">login>

    div>
    <template id="log">
        <div>
            {{parentmsg}}組建
        div>
    template>
body>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                msg: '登陸'
            }
        },
        components: {
            'login': {
                template: '#log',
                props: ['parentmsg']
            }
        }
    })
script>

html>

3. 知识点:

3.1. 如何声明一个组件?

答:首先在

外面写入一个