vue组件递归

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="example1">
    <div id="kk">你好</div>
    <example :num="0"></example>
</div>

<script src="https://unpkg.com/vue/dist/vue.js"></script>

<script type="text/javascript">
    Vue.component('example', {
        name: 'example',
        template: '<span><span style="color:#F00;">{{num}}</span><example :num="num+1" v-if="currNum"></example></span>',
        props: ['num'],
        computed: {
            currNum: function () {
                return this.num < 10
            }
        }
    })

    var r = new Vue({
        el: '#example1'
    })
</script>
</body>
</html>

页面效果:

你好

012345678910

原文地址:https://www.cnblogs.com/zhishaofei/p/6406998.html