Details of the components used in Vue 10-

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Lin16819/article/details/100945368
<!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>Document</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <!-- 一.在html5规范中有的元素指定子元素,如tbody下只能是tr,则可用属性is='组件名', 让tr指向组件row-->
        <table>
            <tbody>
                <tr is='row'></tr>
                <tr is='row'></tr>
            </tbody>
        </table>

        <!-- 二.如果要操作dom,可通过设置ref引用名的形式获取该元素 -->
        <div ref='hello' @click='handleClick'>Hello Suke</div>
    </div>

    <script>
        // 三.子组件中的data:必须是函数,并在该函数中返回对象,在对象中写该子组件的数据
        Vue.component('row',{
            data: function(){
                return {
                    content: 'I am content'
                }                
            },
            template:'<tr><td>{{content}}</td></tr>'
        })

        var vm = new Vue({
            el: '#app',
            methods:{
                handleClick: function(){
                    // $refs是整个vue实例中所有的引用,hello是给上面div设置的引用名,此时可操作该dom
                    alert(this.$refs.hello.innerHTML);
                }
            }
        })
    </script>
</body>
</html>

Guess you like

Origin blog.csdn.net/Lin16819/article/details/100945368